-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Description
Link to the code that reproduces this issue
To Reproduce
- Create a pages-only project (no
app/directory) - Import CSS via a data URL from any page:
// pages/index.tsx
import 'data:text/css,#styled{font-weight:700}'
export default function Home() {
return <div id="styled">This text should be bold</div>
}next dev --turbopack- Visit
/
Global CSS cannot be imported from files other than your Custom <App>.
Due to the Global nature of stylesheets, and to avoid conflicts,
Please move all first-party global CSS imports to pages/_app.js.
Or convert the import to Component-Level CSS (CSS Modules).
Same import works fine in App Router (fun fact: it also works in mixed app+pages projects -> just pages-only projects are affected)
Current vs. Expected behavior
As data:text/css,... is global CSS the Pages Router restriction kicks in and blocks it (at least outside _app.tsx)
The restriction makes sense for guiding users towards CSS Modules, but nobody writes import 'data:text/css,...' by hand. It's generated by tooling (compilers, loaders) that already handles scoping. At that point the guardrail just gets in the way
Real-world impact: this blocks next-yak on Turbopack + Pages Router. In webpack mode, next-yak emits .yak.module.css via inline resource syntax (!=!), so webpack treats it as a CSS Module. Turbopack doesn't support !=!, so next-yak falls back to data:text/css;base64,..., which hits this restriction
Webpack Turbopack
App Router .yak.module.css via !=! → works data:text/css → works
Pages Router .yak.module.css via !=! → works data:text/css → fails
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Relevant Packages:
next: 16.2.0-canary (latest canary)
react: 19.x
typescript: 5.xWhich area(s) are affected? (Select all that apply)
CSS, Pages Router, Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
the fix would be small:
the global CSS validation in crates/next-api/src/module_graph.rs already exempts node_modules imports. same treatment for data URL modules (path filename starts with data:) fixes this