-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Uncaught ReferenceError: process is not defined, won't build in Webpack #55
Comments
This is caused by webpack 5 being broken, and not polyfilling node globals by default. You’ll have to fix it by adding stuff to your config; see https://blog.sindresorhus.com/webpack-5-headache-b6ac24973bf1 |
I see. A fix seems to be using ProvidePlugin to polyfill the global Relevant snippet // ...
plugins: [
new webpack.ProvidePlugin({
// Make a global `process` variable that points to the `process` package,
// because the `util` package expects there to be a global variable named `process`.
// Thanks to https://stackoverflow.com/a/65018686/14239942
process: 'process/browser'
})
],
// ... |
I just stumbled upon the same issue, while using other 3rd-party browser targeted library, that depends on I'm not using Reading the responses in this thread confused me even further.
For me "at some version some tool were somehow affecting user codebase by default" do not translate into nor justify the statement of " If library requires some Node.js polyfills to run in browser -- it is not browser-ready. It's just Node.js library. Summarizing it, I suppose that we have to either:
"User must update config" is not "browser-ready". One of those statements must go, I believe. |
@lildeadprince it means that you shouldn’t are while using a working node module bundler, the definition of which requires the decade-long behavior of polyfilling node builtins and globals automatically. In other words, you shouldnt have to care about it, but some bundlers have chosen to intentionally break themselves and force you to care about it. You can either fix those bundlers via config, use a non-broken bundler, or jump through innumerable hoops trying to work around the way the ecosystem has always worked. This package is browser-ready. The problem is that your bundler isn’t. |
Thank you for explaining your opinion. Not that I agree with it, but I accept it as a final statement on this topic. And also thank you for a quick reply. Node.js don't even need bundling. Bundlers naturally are browser only tool, so "non-brower-ready bundler" (Vite itself even) sounds like nonsense to me. And I don't think attempts of injections of some usually totally unrelated code (until none of Node internals are not in ES or browser API spec) is their job by default. I don't know why is it expected from bundler to "fix" code full of process.env, .std*, .nextTick, etc. Looks like a separate feature, not as a solid "must". Well, maybe I'm wrong. Will try exploring more opinions on later. Ultimately I'm glad that TIL, that there is another solid opinion around and I have to and will be aware of that in future. Thanks. |
Just my 2 cents: because this package targets browsers and a lot of users happen to use "a bundler that isn't browser-ready", it would actually be great if this incompatibility would be mentioned in the readme with a link to this thread. Would you be interested in a PR in this matter? |
Sure, if it lists a few bundlers that are broken by default (like webpack 5), and a few that work by default (like webpack < 5), that seems reasonable. |
I tried building this in my project with latest webpack and got the following error:
Seems like webpack is hitting a
require('util/')
and bundling Node.js's implementation of util, which has Node.js only code, hence the error above.I stripped it down to a simple test case.
webpack.config.js
entry.js
package.json
testtt.html
Also here's the built files. You can copy and run something like
python -m http.server
to open, or another small http file server.testtt.zip
I think this can be worked around by also polyfilling
util
in the webpack config, but there is no util-browserify package that I've found yet on npmThe text was updated successfully, but these errors were encountered: