Compiler does not place css @imports in own style tags the way babel used to.
See original GitHub issueWhat version of Next.js are you using?
12.0.7
What version of Node.js are you using?
14.18.1
What browser are you using?
chrome
What operating system are you using?
mac0s
How are you deploying your application?
vercel
Describe the Bug
I just got bit in the upgrade.
In nextjs v10, this is considered valid:
* {
font-family: "Abril Fatface";
}
@import url('https://fonts.googleapis.com/css2?family=Abril+Fatface&display=block');
This works because each @import
statement is wrapped in its own style
tag.
In nextjs v12, @import
statements are not wrapped in their own style
tag.
Expected Behavior
I expect each @import
statement is wrapped in its own style
tag.
To Reproduce
In nextjs v12, add this to global.css
* {
font-family: "Abril Fatface";
}
@import url('https://fonts.googleapis.com/css2?family=Abril+Fatface&display=block');
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:19 (7 by maintainers)
Top Results From Across the Web
Importing CSS files in Isomorphic React Components
The reason is that Babel is just a transpiler for what's coming in ES6, and ES6 will not allow you to import CSS...
Read more >css-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >Options - Babel.js
Options can be passed to Babel in a variety of ways. When passed directly to Babel, you can just pass the options object....
Read more >JSX In Depth - React
You can also use the self-closing form of the tag if there are no children. ... and correspond to a component defined or...
Read more >Included Filters — webassets 0.12.1 documentation
If not set the filter will try to run babel as if it's in the system path. ... POSTCSS_BIN: Path to the postcss...
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
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm that this issue is still occurring with nextjs 12.1.0 production mode. Does anyone know any alternative way to load google fonts while using swcMinify?
Edit: The issue does not seem to be related to swc, and occurs even with swcMinify = false in nextjs 12+ versions; I worked around it in the following way:
Confirming that @scottccoates mentioned above.
I had Tailwind definitions at the top of the file and then a font Google Font import afterwards like this
Moving the imports as the top first thing on the file, solved the problem
I also confirm this working correctly on Next 11
Hope this is useful.