-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I had a similar setup (Next.js app in docs/ + Yarn workspaces packages). A couple of things helped: Transpile local workspaces @type {import('next').NextConfig}
const nextConfig = {
transpilePackages: ['package-a', 'package-b'], // your workspace packages
// If you fall back to webpack:
experimental: { esmExternals: 'loose' }, // optional (webpack-only)
};
module.exports = nextConfig; This tells Next to bundle/transform your internal packages (replaces next-transpile-modules). ESM externals & find-up // ESM usage inside your package:
import { findUp } from 'find-up';
// or dynamic:
const { findUp } = await import('find-up'); Alternatively, pin a CJS-compatible version of find-up as a quick test. Turbopack vs webpack Package exports {
"name": "package-a",
"type": "module",
"exports": {
".": {
"import": "./dist/index.js"
}
}
} (Or provide both ESM/CJS if you need compatibility.) After adding the above, remove lockfile and reinstall to ensure links are fresh:
Then next dev (Turbopack) should start without the import error; webpack + esmExternals: 'loose' should also work if you prefer webpack for now. |
Beta Was this translation helpful? Give feedback.
-
Yeah, the reason webpack “works” but Turbopack fails is that That’s why // in ESM files
import { findUp } from 'find-up'
// in CJS
const { findUp } = await import('find-up')
You don’t really control Next’s output format (CJS vs ESM) — the key is making your own packages and imports ESM-friendly.
If you need a quick workaround: pin find-up@5 and later move to ESM when Turbopack’s interop improve |
Beta Was this translation helpful? Give feedback.
I had a similar setup (Next.js app in docs/ + Yarn workspaces packages). A couple of things helped:
Transpile local workspaces
In docs/next.config.js, make sure your internal packages are transpiled by Next (works with both Turbopack and webpack):
This tells Next to bundle/transform your internal packages (replaces next-transpile-modules).
Docs: Next.js transpilePackages.
Next.js
ESM externals & find-up
find-up is ESM-only in…