Open zollf opened 7 months ago
Have you found a workaround for this issue? I am using a monorepo (turbo with pnpm workspaces) and I have the same problem.
Have you found a workaround for this issue? I am using a monorepo (turbo with pnpm workspaces) and I have the same problem.
@DavieReid We've just placed this package.json
{
"type": "module"
}
in all our project folders.
Have you found a workaround for this issue? I am using a monorepo (turbo with pnpm workspaces) and I have the same problem.
@DavieReid We've just placed this
package.json
{ "type": "module" }
in all our project folders.
Thanks, I am doing pretty much the same thing.
Link to the code that reproduces this issue
https://github.com/zollf/nextjs-standalone-esm-bug
To Reproduce
"type": "module"
inpackage.json
for ESMoutput: 'standalone'
in next confignpm run build custom-dir
node custom-dir/.next/standalone/custom-dir/server.js
Current vs. Expected behavior
When trying to run a standalone server it will result in a reference error:
ReferenceError: require is not defined in ES module scope, you can use import instead
. Upon inspectionserver.js
is using CommonJS, not ESM code.Looking at the build utils this potentially could be the cause:
https://github.com/vercel/next.js/blob/bef716ad031591bdf94058aaf4b8d842e75900b5/packages/next/src/build/utils.ts#L1948-L1950
Our package.json location is one more directory away.
The expected outcome is for standalone output to be ESM code with a custom directory
Provide environment information
Which area(s) are affected? (Select all that apply)
Module resolution (CJS / ESM, module resolving)
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
No response