Global CSS cannot be imported from files other than your Custom <App>.
See original GitHub issue
Expected Behavior
Given a default NextJs app that imports a shared react lib with a default component that uses either css or cssModule imports should just work, no need to adapt next.config.js
as both imports are supported by default in NextJs.
Is this a regression? Not sure, I am able to reproduce with brand new workspace and latest version of every plugin.
Steps to Reproduce
- npx create-nx-workspace test-bug [choose empty setup]
- npm i -D @nrwl/next
- nx generate @nrwl/next:application --name=test-bug
- nx generate @nrwl/react:library --name=shared-library
- in the generated nextjs app add the shared component to the render function
- try run the app
nx serve test-bug
- try renaming components css file to =>
xxx.module.css
and it’s corresponding import
Failure Logs
warn - Detected next.config.js, no exported configuration found. https://err.sh/vercel/next.js/empty-configuration
info - automatically enabled Fast Refresh for 1 custom loader
info - Using external babel configuration from /Users/danielq/Projects/test-workspace/apps/test-bug/.babelrc
event - compiled successfully
[ ready ] on http://localhost:3000
event - build page: /next/dist/pages/_error
wait - compiling...
event - compiled successfully
event - build page: /
wait - compiling...
error - /Users/danielq/Projects/test-workspace/libs/shared-components/src/lib/shared-components.css
Global CSS cannot be imported from files other than your Custom <App>. Please move all global CSS imports to pages/_app.tsx. Or convert the import to Component-Level CSS (CSS Modules).
Read more: https://err.sh/next.js/css-global
Location: ../../libs/shared-components/src/lib/shared-components.tsx
Environment
nx : Not Found @nrwl/angular : Not Found @nrwl/cli : 10.2.1 @nrwl/cypress : 10.2.1 @nrwl/eslint-plugin-nx : 10.2.1 @nrwl/express : Not Found @nrwl/jest : 10.2.1 @nrwl/linter : 10.2.1 @nrwl/nest : Not Found @nrwl/next : 10.2.1 @nrwl/node : Not Found @nrwl/react : 10.2.1 @nrwl/schematics : Not Found @nrwl/tao : 10.2.1 @nrwl/web : 10.2.1 @nrwl/workspace : 10.2.1 typescript : 3.9.7
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:29 (10 by maintainers)
Top Results From Across the Web
Next.js Global CSS cannot be imported from files other than ...
So you have a global css that must be included on every single page, it has to be imported into the app file...
Read more >Next.js: Global CSS cannot be imported from files other than ...
Global CSS errors can happen because of the improper configuration of next.config.js file. If you are using next.config.js , make sure it is ......
Read more >css-global | Next.js
An attempt to import Global CSS from a file other than pages/_app.js was made. Global CSS cannot be used in files other than...
Read more >Solution: Global CSS cannot be imported from files other than ...
Solution: Global CSS cannot be imported from files other than your Custom <App> while creating a new Next.Js App. I was learning Next....
Read more >Global CSS cannot be imported from files other than your ...
Global CSS cannot be imported from files other than your Custom <App> · Developing with Prismic · status-closed, nextjs.
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 Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This will come in 10.4, which will land before American Thanksgiving. We’ll cut a beta release before stable.
Got the similar error when selecting sass for styling while generating a component- nx g component PartyPopper --project=demo --style=scss i dont next.js let you do import ‘./party-popper.scss’; inside components! it has to be css modules .module.css
this is what i had to do to get it working-
code generator should be updated to updated the generate code.
I am happy to create a PR ,but I was not able to find the correct file to make the change inside packages/next folder. @jaysoo ?