question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Undeclared use of node's `process` causes exception in browser

See original GitHub issue

Webpack 5 no longer ships polyfills for nodejs builtin modules, and recommends using this module if a module need util, and the module README does say it should work in a browser. However, the module causes a exception when importing the resulting bundle in the browser:

vendor.2cdb7b12f7e46077b4bd.js:92301 Uncaught ReferenceError: process is not defined

This is causes by this code, which expects to be able to use the nodejs process module without importing it:

https://github.com/browserify/node-util/blob/6b828255a7f407efcd7e4d2c54ddb43256e491fb/util.js#L109

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

29reactions
brenccommented, Nov 9, 2020

I hit this one today as well. Like @ljharb said, looks like you can use ProvidePlugin like this:

// webpack needs to be explicitly required
const webpack = require('webpack')

module.exports = {

/* ... rest of the config here ... */

  plugins: [
    // fix "process is not defined" error:
    // (do "npm install process" before running the build)
    new webpack.ProvidePlugin({
      process: 'process/browser',
    }),
  ]
}

More here.

I wasn’t 100% in love with using the process package for this project so I ended up using DefinePlugin instead:

plugins: [  
  new webpack.DefinePlugin({
    'process.env.NODE_DEBUG': JSON.stringify(process.env.NODE_DEBUG)
  })
]

Both solutions seem to work.

7reactions
SVV-teamcommented, Feb 19, 2022

For those who use Vite or Nuxt3

Error with process.env.NODE_DEBUG

solutions ==>

  1. Install polyfill using npm or yarn
yarn add @esbuild-plugins/node-globals-polyfill
  1. Add to your vite or nuxt config (NUXT example, vite similar)
import {NodeGlobalsPolyfillPlugin} from '@esbuild-plugins/node-globals-polyfill'

export default defineNuxtConfig({
vite: {
        optimizeDeps: {
            esbuildOptions: {
                define: {
                    global: 'globalThis'
                },
                plugins: [
                    NodeGlobalsPolyfillPlugin({
                        process: true,
                        buffer: true
                    }),
                ]
            }
        },
    }
})

With this config Web3 and other work perfect

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught errors in Node.js and the browser
This article looks into what happens with unhandled errors both in Node.js and in the browser.
Read more >
How to Throw Exceptions in Node.js - Rollbar
URIError : this error occurs whenever encodeURI or decodeURI are given invalid parameters.
Read more >
Make node.js not exit on error - Stack Overflow
Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the ...
Read more >
Process | Node.js v19.3.0 Documentation
Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the ...
Read more >
Let It Crash: Best Practices for Handling Node.js Errors on ...
Unhandled exceptions inherently mean that an application is in an undefined state...The correct use of 'uncaughtException' is to perform ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found