-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to include CSS from node_modules in project? #10059
Comments
Delete your |
I upgraded and now I get this. This is whole message
UPDATE
it is same one that didn't work 30 minutes ago. I had to restart PC for it to work. Looks like it was problem on my side. |
The error you saw was because you needed to move that CSS import to the You'd need to create a So import React from 'react'
import 'bootstrap/dist/css/bootstrap.min.css';
import 'any-other-css-you-want.css';
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
} Here is the help article that is linked in that error. |
I understand now. Thank you so much for clarifying this to me. |
Sorry, yeah — that read more link will work soon. |
Do note, |
Oh well. Thanks for the heads up. This is usefull information. I will immediately use method you guys wrote. Thank you :) |
[ error ] ./node_modules/react-datepicker/dist/react-datepicker.css 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> .react-datepicker-popper[data-placement^="bottom"] .react-datepicker__triangle, .react-datepicker-popper[data-placement^="top"] .react-datepicker__triangle, .react-datepicker__year-read-view--down-arrow,
| .react-datepicker__month-read-view--down-arrow, |
[ error ] ./node_modules/@fortawesome/fontawesome-svg-core/styles.css 1:8
Module parse failed: Unexpected token (1:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> svg:not(:root).svg-inline--fa {
| overflow: visible; }
| |
@muhaimincs I guess what @Timer meant by removing However to use Working example for this would be, and append webpack to your module.exports
|
@Timer I've been seeing this issue pop up lately with all the new changes in 9.x, There are a lot of third party packages that ask us to import their .css files from the node_modules folder. Do you see next.js adding support for this any time soon? I feel like the _app.js is having to add all these .css files directly, I'll have eventually like 10 different CSS files from all these different packages that I have to load globally when I'm only trying to load them when the specific component is being used. I would love to know if there's already a solution for this or any recommendations would be greatly appreciated! |
any updates? |
+1 — this error also crops up when trying to implement styled-components: https://github.com/zeit/next.js/tree/canary/examples/with-styled-components [ETA: I'd be happy to help contrib a fix if pointed in the right direction :] |
thanks @M1ck0 it works! I doesn't work sadly! |
wont the size of _app.js will be heavy if we have to import tons of third party libraries css from node_modules? Is there any other solution for this? |
Well. If you are using tons of libraries for UI there _app is going to be heavy. Solution would be to import CSS files in components/pages that need them and not in _app, but I am not sure that this is possible. |
This comment has been minimized.
This comment has been minimized.
@M1ck0 I don't think so. Because when building it throws an error saying |
As I said.. It is not possible now but it might be solution if implemented.. not sure.. |
so what's the solution to be implemented? |
Same problem with me! Only with the import of css in my package of components. |
Anyone have a workaround for this? To use a library like full calendar it exports its own css. |
I got here! https://github.com/vercel/next.js/blob/master/errors/css-npm.md I didn't find an alternative solution and ended up removing the css import pro user in the application |
best option I found was to use the postinstall hook and run a node script that copies the css files out of the node_modules into my public dir, then load those files with a link tag.
makes sense to only load these files on the relevant pages. |
can you please let me know what is postinstall hook or can you show me some example for this |
it's an npm hook., after the install command is finished the post install is executed. package.json
copy_assets_to_public.js
|
Duplicate of #12079, please move all correspondence there! |
I am trying to
import 'bootstrap/dist/css/bootstrap.min.css';
in my next.js project but I get following error
Module parse failed: Unexpected token (6:3) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file
I have
next.config.js
file in root directory of project. It has this configurationI followed this comment which apparentlyworks but not for me. Any ideas why?
The text was updated successfully, but these errors were encountered: