TypeError: routesManifest.dataRoutes is not iterable · 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 — or at server boot, when next start reads a routes-manifest.json a different build wrote
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. One error in this family is not a build failure at all: routesManifest.dataRoutes is not iterable throws at server boot, after a build that printed nothing wrong.
webpack() function. Fix by configuring turbopack.rules and resolveAlias, replacing non-ESM deps, and using --webpack only as a temporary fallback. One failure in this family is not a build failure: TypeError: routesManifest.dataRoutes is not iterable throws at server boot, because next start read a routes-manifest.json a different build wrote — clear .next and rebuild with the same Next version that boots the server. Read node_modules/next/dist/docs/ before assuming old patterns work.How do I fix Turbopack build error?
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 componentNot a developer? We fix this for you at a fixed price: $299 emergency triage, done in 48 hours or fully refunded. Not sure what else is broken? Send the repo for the $49 audit.
What if the quick fix doesn't work?
01 · routesManifest.dataRoutes is not iterable — rebuild the manifest, then match the versions
routesManifest.dataRoutes is not iterable means the production server parsed .next/routes-manifest.json and found no dataRoutes key. In next@16.2.3 the read is unguarded — node_modules/next/dist/server/lib/router-utils/filesystem.js line 228 runs for (const route of routesManifest.dataRoutes) straight after JSON.parse, so a missing key throws instead of degrading. Every manifest next build writes carries it: node_modules/next/dist/build/generate-routes-manifest.js line 54 initialises dataRoutes: [], and node_modules/next/dist/build/index.js line 1560 only replaces that empty array when the app has Pages Router getServerSideProps or getStaticProps routes. An App-Router-only app is expected to ship "dataRoutes": [] — an empty array is iterable and is not the problem.
So the key is absent only when the file was not written by this version’s next build: a .next restored from a CI cache built on an older major, a runtime that installed a different next than the build step, a standalone output where the manifest was never copied next to server.js, or a truncated upload. Clearing .next and rebuilding fixes the first; only version parity fixes the rest.
01# 1. Confirm what the server is actually reading02node -e "const m=require('./.next/routes-manifest.json'); \03 console.log('version', m.version, '| dataRoutes', Array.isArray(m.dataRoutes) ? m.dataRoutes.length : m.dataRoutes)"04# Expected on next@16.x: version 3 | dataRoutes 0 (App Router only — empty is fine)05# Broken: undefined | dataRoutes undefined06 07# 2. Rebuild the manifest from scratch08rm -rf .next && npx next build09 10# 3. Match the binary that boots the server to the one that built11npx next --version # run this on the SERVER, not your laptop12node -p "require('./package.json').dependencies.next"13 14# 4. standalone output — the manifest must travel with server.js15ls .next/standalone/.next/routes-manifest.json02 · Replace @svgr/webpack with build-time codegen
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" }03 · MDX with the native @next/mdx package
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);04 · Dynamic require bridge for CommonJS-only dependencies
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}Does this error survive a redeploy, or does it only reproduce locally?
Neither, reliably — and that is what makes it confusing. The corpus around this error is written from local reproduction, but the impressions land on a build-log symptom, so the two populations are describing different moments. A routes-manifest.json problem does not reproduce on a laptop that just ran next build and next start back to back against the same node_modules: that sequence guarantees version parity and a fresh manifest, which is exactly the state the error cannot occur in. It reproduces where the build step and the boot step are separated — a cached .next, a Docker layer, a standalone bundle, an artefact uploaded between two jobs. A redeploy clears it whenever the redeploy also rebuilds .next from a clean checkout, and leaves it in place whenever the platform restores a build cache instead.
If the manifest is regenerated but the error persists
Every competing page stops at “delete .next”. When that does not clear it, the second cause is that the next package resolving at boot is not the one that built the directory. Run npx next --version on the machine that starts the server rather than on the machine that built, and compare it to the next entry in package.json. Two configurations produce the mismatch quietly: a lockfile installed with a different resolution on the runtime image than in CI, and a distDir override that points next start at a directory some other build wrote. Both leave a perfectly valid manifest on disk — just not one this reader understands. If the versions match and the boot still throws, you can send us the failing build — the build log paired with the step-1 manifest read is enough to separate a stale artefact from a version mismatch without access to the repository.
Send your app URL. A senior engineer records a 10-minute teardown.
Free, and fully async — no call to book. A senior engineer walks your app on video: what’s broken, what’s risky, what to fix first. In your inbox within 24 hours. Want the code read line by line instead? Send the repo for the $49 audit.
Why do 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.
Diagnose Turbopack build error by failure mode
Which Turbopack build failures are not this error? Manifest-shape failures and loader failures produce similar-looking red text at different moments in the pipeline, and only one of the four rows below is helped by falling back to --webpack. Read the moment the error appeared — build, or first request after boot — before choosing a fix.
| Error text | When it appears | What it actually is | Does --webpack help? |
|---|---|---|---|
| TypeError: routesManifest.dataRoutes is not iterable | Server boot / first request, after a clean build | Manifest shape. next start parsed a routes-manifest.json with no dataRoutes key, so it did not come from this version's next build | No — the manifest reader is bundler-agnostic |
| Module not found: Can't resolve '<pkg>' | During next build | Resolution. A CommonJS-only dependency, or a package whose exports field advertises ESM it does not ship | Often yes, as a temporary bridge |
| Turbopack could not parse /*! webpackChunkName */ | During next build | Loader. A webpack-only loader or magic comment that Turbopack does not execute | Yes — this is the case --webpack exists for |
| Could not find a production build in the '.next' directory | Server boot | Missing artefact. distDir has no BUILD_ID — the build never ran, or ran into a different directory | No — nothing was built to fall back to |
Which AI builders ship Turbopack build error?
How often each AI builder ships this error and the pattern that produces it.
| Builder | Frequency | Pattern |
|---|---|---|
| Lovable | Every Next 16 scaffold | Uses @svgr/webpack — silently ignored by Turbopack |
| Bolt.new | Common | Adds custom webpack() function that Turbopack does not read |
| v0 | Common | Pulls in CJS-only chart libraries that fail ESM resolution |
| Cursor | Sometimes | Uses deprecated experimental flags from Next 14 |
| Replit Agent | Rare | Mixes next dev (Turbopack) with next build --webpack — inconsistent output |
Related errors we fix
How do I stop Turbopack build error recurring?
- →Read node_modules/next/dist/docs/ whenever you upgrade Next.js major versions.
- →Prefer ESM-only dependencies; check the package.json `type` and `exports` fields before installing.
- →Replace webpack-specific loaders with build-time codegen when possible (svg → tsx at prebuild).
- →Keep both next build and next build --webpack green during migration windows.
- →Add a CI step that runs `next build` with no flags so Turbopack regressions fail loudly.
- →Never restore a .next directory from cache across a Next.js major upgrade — the manifests inside it are versioned artefacts, and a restored one is what produces routesManifest.dataRoutes is not iterable at boot.
- →Pin the same next version in the build image and the runtime image, and assert it: a one-line `npx next --version` step in the release pipeline catches the mismatch before the server does.
- →Give every parallel route slot an explicit default.js — Next 16 fails the build without one; return null or call notFound() to keep the old behavior.
- →Visually diff key pages after switching bundlers — Turbopack can concatenate CSS files in a different order than webpack, shifting which rules win.
Still stuck with Turbopack build error?
Turbopack build error questions
What does "TypeError: routesManifest.dataRoutes is not iterable" mean?+
Is routesManifest.dataRoutes is not iterable a Turbopack build error at all?+
The manifest was regenerated and the error persists — what is the second cause?+
Why did Turbopack break after upgrading to Next.js 16?+
Can I still use custom webpack config with Turbopack?+
How do I fall back to webpack in Next.js 16?+
What is the canonical SVG-as-React-component replacement for SVGR under Turbopack?+
How long does a Turbopack migration take?+
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.
Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.