`node:crypto` issues in Next.js
inlet opened this issue · 7 comments
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
5.9.0
Plugin version
No response
Node.js version
20.6.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Sonoma 14.0
Description
When using fast-json-stringify
in a Next.js site (client component), it breaks because it refers to node:crypto
.
It outputs:
Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:crypto
./node_modules/fast-json-stringify/index.js
Steps to Reproduce
See this codesandbox demo
Expected Behavior
It should work in the browser as well. When running this it should not prompt this error but instead continue compiling and rendering the result in the browser
FYI Version 5.8.0
dit work in the browser using Next app
cc @Ethan-Arrowood wdyt?
Interesting. There must be some kind of polyfill? happening that gets broken by the node:
prefix. I'll crosspost to the Next.js crew and let them investigate further.
Okay as I expected, Next.js does polyfill crypto
, but they say this is not great and that using fast-json-stringify
in a client component is wrong (since you shouldn't be using Node.js deps in a client component). When node:
was added, Next.js started failing (as expected). They've kept in their polyfill as to not break a ton of existing projects, but have started hard failing when they notice node:
in imports. @mcollina I think you are okay to add them back in if this module is truly Node.js only (which I do believe it is).
I agree with @Ethan-Arrowood here, if fast-json-stringify
is ment for node only then it’s good practice to bring back the node:
prefixes in