Global CSS cannot be imported from within node_modules.
See original GitHub issueBug report
I can’t import a css file from a node_modules
3rd party library as described here (https://nextjs.org/docs/basic-features/built-in-css-support#import-styles-from-node_modules).
This is the error I’m getting:
./node_modules/react-datepicker/dist/react-datepicker.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/@edooking/ui/src/elements/DatePicker/DatePicker.tsx
It seems this was fixed before here https://github.com/vercel/next.js/issues/12079, but since I’m able to reproduce the issue again on Next.js 10.0.3
I’m re-opening the issue.
To Reproduce
Try to import a CSS from a 3rd party lib.
Expected behavior
To be able to import css
System information
- OS: macOS
- Chrome
- Version of Next.js: 10.0.3
- Version of Node.js: 14.4.0
- Deployment: vercel
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:28
- Comments:20 (5 by maintainers)
Top Results From Across the Web
Next.js Global CSS cannot be imported from files other than ...
I came to this answer because I'm trying to use scss inside a component. and apparently now I need to separate my scss...
Read more >Global CSS cannot be imported from within node_modules
18 Day 11 77. Combinations Given two integers n and k, return all possible combinations of k numbers out of the range [1,...
Read more >Next.js: Global CSS cannot be imported from files other than ...
When migrating to Next.js 9+, I was running into an issue where I could not import global styles from any file other than...
Read more >Next.js Global CSS cannot be imported from files other than ...
CSS : Next.js Global CSS cannot be imported from files other than your Custom App [ Beautify Your Computer ...
Read more >Using CloudScape with NextJS - Andrew Stacy
node_modules/@cloudscape-design/components/alert/styles.scoped.css Global CSS cannot be imported from within node_modules.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
how can you control all 3rd part developer don’t let them import css to their own library, that’s don’t make sense.
This is expected, this particular library is incorrectly publishing css imports to npm, looks like it even publishes JSX. Instead it should be exposed separately:
Importing global css from node_modules is allowed like this in your code:
Main reasons behind this are that we don’t compile node_modules further, meaning those files can’t be found during pre-rendering and would crash your application. It’s also not compatible with esmodules so looking to the future it’ll cause issues.
An example of correctly publishing a library like this is https://reach.tech/styling/