Replies: 2 comments
-
Proposed fix + why it happens
Minimal workaround (no extra bloat):
npm i process
# or
yarn add process
// next.config.js (CJS)
module.exports = {
webpack: (config, { isServer, webpack }) => {
if (!isServer) {
config.resolve.alias = {
...config.resolve.alias,
'node:process': 'process/browser',
process: 'process/browser',
};
config.plugins.push(
new webpack.ProvidePlugin({
process: ['process/browser'],
})
);
}
return config;
},
};
// next.config.mjs
import { ProvidePlugin } from 'webpack';
export default {
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.alias = {
...config.resolve.alias,
'node:process': 'process/browser',
process: 'process/browser',
};
config.plugins.push(new ProvidePlugin({ process: ['process/browser'] }));
}
return config;
},
}; This mirrors your Why not enable by default? References |
Beta Was this translation helpful? Give feedback.
-
Hi! My take here is that, because As the package itself says:
So, if it were to automatically replace In a way, you do well to judge those webpack hacks, and the type of LLM answer above, because "bypassing" this error, is but ignoring that your module graph has ended up bringing code meant for the server into the browser. I am resisting saying but, oh well, It is like having |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
import process from 'node:process'
it should work just as well as the globalprocess
UnhandledSchemeError
- NextJS knows all about nodeJS's process library and has a polyfill and default behaviours definedNon-Goals
node:
prefix imports.process
is already a special case because NextJS usesprocess.env
in both server and client code.Background
Currently, importing files that contain imports from
node:process
works fine on the NextJS server, but when these files are bundled for the client by Webpack 5, it may fail with this error:This is surprising because NextJS already handles
process
in client bundles with built-in default behaviours. Global process and importing fromnode:process
are directly equivalent so it's surprising that one should work and one should fail.There's a workaround but it's quite obscure and I don't think it's documented anywhere:
Proposal
Automatically map
node:process
imports to use pre-existing built-inprocess
polyfill (config.resolve.fallback.process
) in web builds.Beta Was this translation helpful? Give feedback.
All reactions