afterbuild/ops
ERR-746/Next.js 16 · Turbopack
ERR-746
Module not found: Can't resolve 'some-cjs-only-package' · Turbopack could not parse /*! webpackChunkName */

appears when:After upgrading to Next.js 16 where Turbopack becomes the default bundler for both dev and build, breaking webpack loaders and CommonJS-only imports

Turbopack build error in Next.js 16

Next 16 defaults to Turbopack. Webpack loaders no longer run, CommonJS-only packages need ESM wrappers, and custom webpack config is ignored. Most fixes are additive.

Last updated 17 April 2026 · 7 min read · By Hyder Shah
Direct answer
Turbopack build error in Next 16 is almost always an incompatible webpack loader, a CommonJS-only dependency, or an ignored webpack() function. Fix by configuring turbopack.rules and resolveAlias, replacing non-ESM deps, and using --webpack only as a temporary fallback. Read node_modules/next/dist/docs/ before assuming old patterns work.

Quick fix for Turbopack build error

next.config.ts
typescript
01// next.config.ts — Next.js 16 config with Turbopack rules and webpack fallback path02import type { NextConfig } from "next";03 04const config: NextConfig = {05  // Turbopack is default in Next 16 — this block configures it06  turbopack: {07    rules: {08      // SVG as React component using the .svg?component suffix09      "*.svg?component": {10        loaders: ["@svgr/webpack"],11        as: "*.js",12      },13    },14    // module resolution aliases (replaces webpack config.resolve.alias)15    resolveAlias: {16      "@": "./src",17      "@lib": "./src/lib",18    },19  },20  // Optional: keep a legacy webpack config that only fires when you opt out21  // Run: next build --webpack to use the legacy path as a temporary fallback22};23 24export default config;25 26// Usage:27//   next dev           # Turbopack (default)28//   next build         # Turbopack (default)29//   next build --webpack   # legacy webpack fallback when a dep still breaks30//   import icon from "./hero.svg?component"; // renders as React component
Next 16 config — turbopack.rules replaces webpack loaders, resolveAlias replaces config.resolve.alias

Deeper fixes when the quick fix fails

01 · Replace @svgr/webpack with build-time codegen

scripts/generate-svg-components.ts
typescript
01// scripts/generate-svg-components.ts — run at prebuild to emit .tsx from .svg02import { readFileSync, writeFileSync, readdirSync } from "fs";03import { join, parse } from "path";04import { transform } from "@svgr/core";05 06const srcDir = "src/assets/icons";07const outDir = "src/components/icons";08 09for (const file of readdirSync(srcDir).filter((f) => f.endsWith(".svg"))) {10  const svg = readFileSync(join(srcDir, file), "utf8");11  const name = parse(file).name.replace(/(^|-)(\w)/g, (_m, _d, c) => c.toUpperCase());12  const jsx = await transform(svg, { typescript: true, ref: true }, { componentName: name });13  writeFileSync(join(outDir, `${name}.tsx`), jsx);14}15 16// package.json17// "scripts": { "prebuild": "tsx scripts/generate-svg-components.ts" }
Committed .tsx files are bundler-agnostic. Works under Turbopack, webpack, Vite, or esbuild

02 · MDX with the native @next/mdx package

next.config.ts
typescript
01// next.config.ts — @next/mdx supports Turbopack natively in Next 1602import createMDX from "@next/mdx";03import type { NextConfig } from "next";04 05const withMDX = createMDX({06  extension: /\.mdx?$/,07  options: {08    remarkPlugins: [],09    rehypePlugins: [],10  },11});12 13const config: NextConfig = {14  pageExtensions: ["ts", "tsx", "md", "mdx"],15};16 17export default withMDX(config);
Replaces mdx-loader — @next/mdx is the first-party solution that works on both bundlers

03 · Dynamic require bridge for CommonJS-only dependencies

lib/legacy-cjs-dep.ts
typescript
01// lib/legacy-cjs-dep.ts — server-only wrapper for a stubborn CJS package02import { createRequire } from "node:module";03 04export function loadLegacy() {05  // Only call from server components or route handlers06  const require = createRequire(import.meta.url);07  const legacy = require("legacy-cjs-only-package");08  return legacy;09}
Use when a dep refuses to ship ESM. Never import from client components — server-only

Why AI-built apps hit Turbopack build error

Next.js 16 promoted Turbopack from an experimental dev server to the default bundler for both next dev and next build. Turbopack is written in Rust and shares very little code with webpack. It does not execute webpack loaders. It does not read your webpack() function in next.config.js. It has its own much smaller configuration surface under the turbopack key, and it prefers ESM packages over CommonJS. The compatibility gap is well-documented but invisible to code that was written before Next 16.

AI builders scaffold Next.js apps with boilerplate from 2023 and 2024: @svgr/webpack for SVG imports, mdx-loader for markdown, raw-loader for text files, a webpack() function that adds a resolve alias. All of these were standard. All of them are silently ignored or explicitly failing under Turbopack. Same source code, completely different build result.

CommonJS is the second pain point. A surprising number of packages still ship CommonJS only or ship an ESM wrapper with a broken package.json exports field. Turbopack follows Node's strict resolution rules, so if the package advertises ESM but the file is actually CommonJS, Turbopack fails to parse it. Webpack was permissive and would fall back to CommonJS. Turbopack does not. The fix is to install a patched version or wrap the import in a dynamic require.

Experimental flags from earlier Next.js versions also cause failures. Flags like serverActions.bodySizeLimit moved into stable config under different names, and some options were removed entirely. Read node_modules/next/dist/docs/ before shipping. The docs list every deprecated flag and its replacement. AI-generated code rarely cross-references deprecations because the training data predates the release.

Turbopack build error by AI builder

How often each AI builder ships this error and the pattern that produces it.

AI builder × Turbopack build error
BuilderFrequencyPattern
LovableEvery Next 16 scaffoldUses @svgr/webpack — silently ignored by Turbopack
Bolt.newCommonAdds custom webpack() function that Turbopack does not read
v0CommonPulls in CJS-only chart libraries that fail ESM resolution
CursorSometimesUses deprecated experimental flags from Next 14
Replit AgentRareMixes next dev (Turbopack) with next build --webpack — inconsistent output

Related errors we fix

Stop Turbopack build error recurring in AI-built apps

Still stuck with Turbopack build error?

Emergency triage · $299 · 48h turnaround
We restore service and write the root-cause report.
start the triage →

Turbopack build error questions

Why did Turbopack break after upgrading to Next.js 16?+
Next.js 16 makes Turbopack the default bundler for both dev and build. Turbopack is a Rust-based replacement for webpack that does not run webpack loaders, cannot resolve CommonJS-only packages the same way, and ignores most custom webpack config. Any third-party loader (like mdx-loader, raw-loader, file-loader) stops working. Dependencies with only CommonJS exports need an ESM adapter. Check your dependency list against the Turbopack compatibility matrix.
Can I still use custom webpack config with Turbopack?+
No. Turbopack ignores the webpack function in next.config.js entirely when turbopack is the active bundler. Instead you configure Turbopack with the turbopack key — which accepts rules for alias, moduleIdStrategy, and a much smaller set of options. If your webpack config added SVG-as-component support or aliased @/lib to src/lib, translate those rules to Turbopack equivalents. The webpack function is dead code in Next 16 with Turbopack on.
How do I fall back to webpack in Next.js 16?+
Pass `--webpack` to `next dev` and `next build`. This reverts to the legacy bundler. Use this only as a temporary bridge — Next.js 17 may remove webpack entirely and the performance gap favors Turbopack. The right long-term fix is to migrate each incompatible dependency to a Turbopack-friendly alternative rather than permanently running the legacy bundler.
What is the canonical SVG-as-React-component replacement for SVGR under Turbopack?+
Turbopack does not run @svgr/webpack. Two replacements exist: first, use next/image with an SVG file (works for static icons); second, install @svgr/core and transform at build time into real .tsx files, committed to git. A third option is to use heroicons or lucide-react and delete the SVG transforms entirely. AI-generated code often pulls in @svgr/webpack as a legacy pattern; in Next 16 remove it.
How long does a Turbopack migration take?+
A small app with no custom webpack config and all-ESM deps takes zero work — it just runs faster. A medium app with SVGR, MDX, and a couple of CommonJS packages is a four to eight hour migration. A complex monorepo with a custom webpack loader chain is a day or two. Our App Migration service runs full Next.js 16 and Turbopack audits and ships a green build with a CI test suite.
Next step

Ship the fix. Keep the fix.

Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.

About the author

Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.

Sources