Uncaught ReferenceError: process is not defined, won't build in Webpack
See original GitHub issueI tried building this in my project with latest webpack and got the following error:
Uncaught ReferenceError: process is not defined,
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
const path = require('path');
module.exports = {
mode : "development",
entry : { main: "./entry.js" },
output : {
path : path.resolve(__dirname, "dist"),
filename : "[name].js",
library : "datadesk",
libraryTarget : "umd"
},
resolve: {
fallback: {
assert: require.resolve("assert"),
}
},
devtool: "source-map"
};
entry.js
const a = require('assert');
package.json
{
"name": "testtt",
"version": "1.0.0",
"dependencies": {
"assert": "^2.0.0",
"webpack": "^5.65.0"
},
"devDependencies": {
"webpack-cli": "^4.9.1"
}
}
testtt.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="./dist/main.js"></script>
</head>
<body>
</body>
</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.
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 npm
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Bundle.js - Uncaught ReferenceError: process is not defined ...
Try to set the following options in your webpack 4 configuration and check if build still works correctly. module.exports = { // ......
Read more >ReferenceError: “process is not defined” - GIMTEC
In this case, process is not defined in the browser environment, hence the error. The solution is to remove the reference to process...
Read more >Uncaught: ReferenceError: process is not defined. : r/webpack
r/webpack - Uncaught: ReferenceError: process is not defined. So my project was working successfully but once I import the @dfinity/auth-client ...
Read more >Uncaught (in promise) ReferenceError: process is not defined ...
js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it....
Read more >angular uncaught referenceerror: process is not defined
To Reproduce · Create Angular project · Install supabase-js · Create angular service · Import createClient with supabase-js on top of the newly...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see.
A fix seems to be using ProvidePlugin to polyfill the global
process
again, as described in https://github.com/browserify/node-util/issues/57Relevant snippet
@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.