Skip to content

data:text/css imports fail in Pages Router with Turbopack #89900

@jantimon

Description

@jantimon

Link to the code that reproduces this issue

https://github.com/jantimon/next.js/tree/fix/css-data-url-pages-router/test/e2e/css-data-url-global-pages

To Reproduce

  1. Create a pages-only project (no app/ directory)
  2. 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>
}
  1. next dev --turbopack
  2. 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.x

Which 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSSRelated to CSS.Pages RouterRelated to Pages Router.TurbopackRelated to Turbopack with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions