next.js
next.js copied to clipboard
using lodash-es & pnpm & turberepo(monorepo), Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:22 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T6000
Binaries:
Node: 18.15.0
npm: 9.5.0
Yarn: 1.22.19
pnpm: 7.32.4
Relevant packages:
next: 13.4.6
eslint-config-next: 13.4.3
react: 18.2.0
react-dom: 18.2.0
typescript: 4.8.4
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/inflearn/inflearn-ucc-frontend/pull/14
To Reproduce
In the middleware.ts file, we are importing a file that is using lodash-es.
If you run the next build, you will get an error and the build will fail.
I set the config as suggested in the documentation, but the result is the same.
The documentation even says to set the runtime to edge, but when you run the actual build, you get this error: Error: Page /src/middleware provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.
You'll find an error like this
Option values I set
export const config = {
runtime: "experimental-edge",
unstable_allowDynamic: [
"/src/utils/Fetcher.ts",
"/src/@types/schema.ts",
"*/**/node_modules/lodash-es/**",
],
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
Describe the Bug
build will fail.
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime Used by default Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
Expected Behavior
You'll likely encounter an error message like this
../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/_root.js
profile:build: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
profile:build: Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
profile:build:
profile:build: Import trace for requested module:
profile:build: ../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/_root.js
profile:build: ../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/isBuffer.js
profile:build: ../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/lodash.js
profile:build: ./src/utils/Fetcher.ts
profile:build: ./src/@types/schema.ts
profile:build:
profile:build: ../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/template.js
profile:build: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
profile:build: Used by default
profile:build: Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
profile:build:
profile:build: Import trace for requested module:
profile:build: ../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/template.js
profile:build: ../../node_modules/.pnpm/[email protected]/node_modules/lodash-es/lodash.js
profile:build: ./src/utils/Fetcher.ts
profile:build: ./src/@types/schema.ts
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response