Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work on with NextJS Edge runtime (dependency on body-parser -> fs not supported on Vercel Edge) #71

Open
Winwardo opened this issue Aug 12, 2022 · 1 comment

Comments

@Winwardo
Copy link

Hi,
I love this library, very nifty :)

This issue may be too early for you to consider, but next-runtime does not work with a NextJS page using the experimental-edge runtime. https://nextjs.org/docs/advanced-features/react-18/switchable-runtime#page-runtime-option

Specific error message when building:

Failed to compile.
--
18:18:36.899 |  
18:18:36.899 | ./node_modules/body-parser/node_modules/destroy/index.js:16:0
18:18:36.899 | Module not found: Can't resolve 'fs'
18:18:36.899 |  
18:18:36.899 | Import trace for requested module:
18:18:36.899 | ./node_modules/body-parser/lib/read.js
18:18:36.899 | ./node_modules/body-parser/lib/types/json.js
18:18:36.900 | ./node_modules/body-parser/index.js
18:18:36.900 | ./node_modules/next-runtime/runtime/body-parser.js
18:18:36.900 | ./node_modules/next-runtime/handle.js
18:18:36.900 | ./node_modules/next-runtime/index.js
18:18:36.900 | ./src/pages/admin/payments/attempt/[idempotencyKey].tsx

It looks like body-parser has a hard dependency on fs for some reason, and file-system activity is not available in Edge functions.
You only use body-parser in one place, here: https://github.com/smeijer/next-runtime/blob/main/src/runtime/body-parser.ts#L104

Possible fixes:

  • Maybe updating body-parser from 1.19.0 to 1.20.0 (I don't think this will work)
  • Importing only json from 'body-parser (might not actually shake out the fs usage)
  • Find an alternative existing library (I couldn't find an obvious one, and I don't know enough about how you're using it to suggest one)
  • Write your own body parser (possibly very difficult?)
  • Add to documentation that you won't / can't support the edge runtime.

Thanks for all your work here

@smeijer
Copy link
Owner

smeijer commented Aug 24, 2022

Hi! Thanks for the report. I'd be happy to support the edge runtime. Finding a way to remove the fs dependency sounds like a good thing to me. We don't need it. I have no idea (without researching) why bodyparser depends on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants