Reputation: 131
Screenshot for Error: Can't resolve 'process/browser':
I'm hoping someone could help me here. With the Webpack 5 breaking changes with polyfills I was able to use react-rewired to add fallbacks to a config-overrides.js
I npm installed every dependency I could, but I'm still getting this error for "process/browser". I'm not really sure how to identify the problem.
const webpack = require("webpack");
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
assert: require.resolve("assert"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify"),
url: require.resolve("url"),
zlib: require.resolve("browserify-zlib"),
fs: require.resolve("browserify-fs"),
process: require.resolve("process"),
buffer: require.resolve("buffer"),
net: require.resolve("net"),
});
config.resolve.fallback = fallback;
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
]);
return config;
};
Upvotes: 13
Views: 19888
Reputation: 151
I was having the exact same problem, and eventually found this https://github.com/react-dnd/react-dnd/issues/3425#issuecomment-1214554950.
I added 'process/browser': require.resolve('process/browser')
to the fallbacks object without changing anything else and it worked. Hopefully it fixes it for you too.
Upvotes: 15
Reputation: 771
I have a working solution to a similar upgrade that includes these lines in config.override.js
:
let plugs = config.plugins;
plugs.push(new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}));
plugs.push(new webpack.ProvidePlugin({
process: 'process/browser.js'
}))
Here it's calling new webpack.ProvidePlugin(...
for each plug in, not trying to create both in one constructor. Your code above might be adapted to something more like:
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: "process/browser",
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
})
]);
...although I haven't tried this exactly.
Upvotes: 3