Error building pages Module build failed: UnhandledSchemeError: Reading from "node:crypto"

Hi team, I´m trying to move my NextJs app from Vercel to Pages and i´m getting several errors when building my application: Failed to compile. 12:58:58.301 ▲ node:crypto 12:58:58.302 ▲ Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme). 12:58:58.302 ▲ Webpack supports "data:" and "file:" URIs by default. 12:58:58.302 ▲ You may need an additional plugin to handle "node:" URIs. ... 12:58:58.304 ▲ node:fs/promises 12:58:58.305 ▲ Module build failed: UnhandledSchemeError: Reading from "node:fs/promises" is not handled by plugins (Unhandled scheme). 12:58:58.305 ▲ Webpack supports "data:" and "file:" URIs by default. 12:58:58.305 ▲ You may need an additional plugin to handle "node:" URIs. And several more. It seems it is related to using formidable (https://github.com/node-formidable/formidable). Is there anything I should change somewhere to make it work? I use formidable in some functions in the pages/api folder to read the form content. Thanks!
2 Replies
James
James11mo ago
Hey there, it looks like you're running into a build error from Next.js due to trying to use unsupported Node.js modules. I would assume that these are trying to be imported in a route that uses SSR. It looks like you'll probably need to swap it out with a different dependency if you want to be able to use it with Next.js and the edge runtime, or ask the maintainers to make it more compatible with the edge runtime.
Eusebio Trigo
Eusebio Trigo11mo ago
Seems so. It works in Vercel, though. But will check if there is an alternative for edge runtimes. Thanks @skye_31 , yeah, i was expecting node:fs not to be supported (unless a deep integration with an R2 bucket, etc). Formidable is the dependency that we will need to change to succeed in this migration.