Turbopack: `Module Not Found: Can'T Resolve 'Styled-Jsx/Style.Js'` Warning On Pages Router Build With Pnpm
Using styled-jsx in a Pages Router application with pnpm triggers a false 'Module not found' warning during Turbopack builds. The warning occurs because Turbopack's external tracing attempts to resolve styled-jsx/style.js from the project root, but pnpm's strict node_modules layout does not hoist styled-jsx to the root. The build still succeeds and the file is correctly traced via Next.js's own require hooks.
Turbopack's pages server import map marks `styled-jsx/style` as an external with `ExternalTraced::Traced` but does not specify a resolved target. During tracing, the resolver attempts to resolve the external from the tracing root (project root). With pnpm, `styled-jsx` is only available inside `next`'s dependency tree, not hoisted to the root, so resolution fails and emits the warning. The file is later traced correctly via `require_hook_modules` from the `next` package, making the failure harmless but misleading.
1. Create an empty directory with three files:
package.json: { "private": true, "scripts": { "build": "next build" }, "dependencies": { "next": "16.3.8", "react": "19.3.0", "react-dom": "19.3.0" } }
pages/index.js: export default function Home() { return <p>hi</p> }
pages/_app.js: export default function App({ Component, pageProps }) { return (<> <style jsx global>{`:root { --x: 1 }`}</style> <Component {...pageProps} /> </>) }
2. Run `pnpm install`
3. Run `pnpm build`
4. Observe the warning: `Turbopack build encountered 1 warning: ./_ Warning: Module not found: Can't resolve 'styled-jsx/style.js'`
Fixing Code Block
// In crates/next-core/src/next_import_map.rs, locate the pages server
// import map entry for styled-jsx/style and change the external type
// from ExternalType::Traced to ExternalType::Untraced.
pages_server_import_map.insert_exact_alias(
"styled-jsx/style",
External::new(
module,
"styled-jsx/style.js",
ValueType::String,
ExternalType::Untraced, // was ExternalType::Traced
)
.into(),
);
Marking the external as Untraced prevents Turbopack from attempting to resolve the module from the project root during its tracing phase, eliminating the false warning. The styled-jsx file is still traced by Next.js's require_hook_modules mechanism, which resolves it from the next package's own dependencies and includes it in the server build output.
Edge Case Audit
This change relies on require_hook_modules to continue tracing styled-jsx. If that mechanism is modified or removed in future versions, the file may be missing from the build. It is recommended to add a regression test covering pnpm builds to ensure the file remains included. Rollback suggestion: revert the external type to ExternalType::Traced and instead resolve the external from the next package's dependency tree (e.g., by aliasing to next's copy of styled-jsx).