cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.3k stars 126 forks source link

[🐛 Bug]: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime #263

Closed xvpc closed 1 year ago

xvpc commented 1 year ago

next-on-pages environment related information

System: Platform: win32 Arch: x64 Version: Windows 10 Pro CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz Memory: 16 GB Shell: Unknown Binaries: Node: 18.16.0 Yarn: N/A npm: 9.5.1 pnpm: N/A Package Manager Used: npm Relevant Packages: @cloudflare/next-on-pages: 0.10.1 vercel: N/A next: N/A

Description

I keep getting an error when trying to deploy or build my nextjs app using the command npx @cloudflare/next-on-pages

⚡️ @cloudflare/next-on-pages CLI v.1.0.0
⚡️ Detected Package Manager: npm
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲  Next-On-Pages-Vercel-CLI CLI 29.3.0-next-on-pages-fix-3
▲  Installing dependencies...
▲  up to date in 2s
▲  268 packages are looking for funding
▲  run `npm fund` for details
▲  Detected Next.js version: 13.2.4
▲  Detected `package-lock.json` generated by npm 7+...
▲  Running "npm run build"
▲  > tpanime-consumet@0.1.0 build
▲  > next build
▲  info  - Loaded env from D:\github\tpanime-consumet\.env.local
▲  info  - Linting and checking validity of types...
▲  info  - Creating an optimized production build...
▲  <w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (103kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
▲  <w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (104kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
▲  Failed to compile.
▲
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
▲  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
▲
▲  Import trace for requested module:
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  ./node_modules/@consumet/extensions/dist/providers/manga/index.js
▲  ./node_modules/@consumet/extensions/dist/providers/index.js
▲  ./node_modules/@consumet/extensions/dist/index.js
▲
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
▲  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
▲
▲  Import trace for requested module:
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  ./node_modules/@consumet/extensions/dist/providers/manga/index.js
▲  ./node_modules/@consumet/extensions/dist/providers/index.js
▲  ./node_modules/@consumet/extensions/dist/index.js
▲
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
▲  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
▲
▲  Import trace for requested module:
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  ./node_modules/@consumet/extensions/dist/providers/manga/index.js
▲  ./node_modules/@consumet/extensions/dist/providers/index.js
▲  ./node_modules/@consumet/extensions/dist/index.js
▲
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
▲  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
▲
▲  Import trace for requested module:
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  ./node_modules/@consumet/extensions/dist/providers/manga/index.js
▲  ./node_modules/@consumet/extensions/dist/providers/index.js
▲  ./node_modules/@consumet/extensions/dist/index.js
▲
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
▲  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
▲
▲  Import trace for requested module:
▲  ./node_modules/@consumet/extensions/dist/providers/manga/mangahere.js
▲  ./node_modules/@consumet/extensions/dist/providers/manga/index.js
▲  ./node_modules/@consumet/extensions/dist/providers/index.js
▲  ./node_modules/@consumet/extensions/dist/index.js
▲
▲  > Build failed because of webpack errors
▲  Error: Command "npm run build" exited with 1

Reproduction

GitHub repo https://github.com/xvpc/tpanime-consumet It's a simple self-hosted API that uses a library ( @consumet/extensions ) and displays/organizes its information.

Pages Deployment Method

Pages CI (GitHub/GitLab integration)

Pages Deployment ID

No response

Additional Information

This is not the first error I get when trying to deploy a NextJs app into Cloudflare, Everything works fine when I deploy it to Vercel, I don't understand why It's too hard and frustrating to make it Into Cloudflare pages even tho I tried everything, edge runtime, and many other errors were showing before this I kinda feel stuck now and I'm not finding a fix for my problem, well appreciate if you guys put some offered to fix this problem, thanks.

Would you like to help?

james-elicx commented 1 year ago

Hello, it looks like Vercel is failing to build your project. As you may notice, the errors are preceded by a little triangle icon. This indicates that the message comes from the Vercel CLI.

The error you are getting is:

Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime

This is because when you use the Edge Runtime, eval etc. are not allowed. The solution would be modifying your code in such a way that you are not relying on eval or new Function. It looks like this is coming from the @consumet/extensions dependency, so you would need to either find another dependency to use, or create an issue in their repository.

I would also note that taking a look at your API routes, none of them will be compatible with the edge runtime. Please take a look at the Next.js docs for more guidance on Edge API routes. https://nextjs.org/docs/pages/building-your-application/routing/api-routes#edge-api-routes

dario-piotrowicz commented 1 year ago

@xvpc Thanks for the issue, as @james-elicx mentioned eval doesn't work in the edge runtime (regardless on it being run on vercel or cloudflare), so that is not something related to next-on-pages that we can do anything about 😓


If you can remove the code evaluations from your app please do so and let us know if you have other issues (sounds like you've had a bunch with next-on-pages, I'm sorry to hear that 😓)

(PS: I think that your repository is private as it gives me a 404 page)

xvpc commented 1 year ago

Hi, Thanks for responding @james-elicx , @dario-piotrowicz I did some research, and I'm well aware of how edge run-time works now. The problem is I need to use this library for my project since there are no other matches, so I was wondering if there's another way to import it into my API other than 'new function' so I can run it with Edge if not thanks anyway.

dario-piotrowicz commented 1 year ago

ah... from the logs it does look like the library is the one doing the code evaluation 😓 Screenshot 2023-05-23 at 23 36 08

Since that's the case I think it is simply a case of the library not being compatible with the edge runtime 😓

I don't think there is much we can do about it 😓, you could try to run your app on Vercel and use the nodejs runtime, I think that should work (but I can't guarantee it, I haven't really tried)

Alternatively if possible you could not use any runtime at all and generate a static Next.js application and deploy it on Cloudflare Pages (as documented here), everything should work fine but you'd lose SSR (but I am not sure if you have routes that need it in your app).

dario-piotrowicz commented 1 year ago

I'm closing the issue as it doesn't seem like something we can fix on our end

sorry we couldn't help you @xvpc 😢, if you stumble across other issues or want to discuss more this one please let me know