Browserify Error: Uncaught TypeError: Unable to determine current node version in bundle.js

31 views Asked by At

so I recently installed browserify into my application, and I'm getting this error in the Chrome Dev console:

bundle.js:10677 Uncaught TypeError: Unable to determine current node version
    at versionIncluded (bundle.js:10677:9)
    at isCore (bundle.js:10694:28)
    at 71../core.json (bundle.js:15883:21)
    at o (bundle.js:1:265)
    at bundle.js:1:316
    at 67../lib/async (bundle.js:15523:14)
    at o (bundle.js:1:265)
    at bundle.js:1:316
    at Object.<anonymous> (bundle.js:6817:12)
    at Object.<anonymous> (bundle.js:7158:4)

Here is the code in my app that is relevant to the error:



    var current = typeof nodeVersion === 'undefined'
        ? process.versions && process.versions.node
        : nodeVersion;

    if (typeof current !== 'string') {
        throw new TypeError(typeof nodeVersion === 'undefined' ? 'Unable to determine current node version' : 'If provided, a valid node version is required');
    }

So, basically it throws an error when it cannot get the the node version, it will not assign a value to current and it will throw an error later. I have Node v20.6.1, so I don't understand why nodeVersion is undefined or how to fix that. I'm guessing my app is supposed to pass that value when building the webpack but for some reason is not building it correctly. However, I am running the correct command to build the webpack:

 browserify scripts.js -o bundle.js

Any guidance would be appreciated.

I have tried deleting the bundle.js and rebuilding it. I have also tried commenting out the error handling in general, but it needs the node version to assign a value to current for later.

1

There are 1 answers

0
Dani On

The answer was posted here

Apparently, browserify injects the variables when compiling so global and process are different. Global is the node and process is the browser process. I fixed the issue by changing process.versions and process.versions.node to global.process.versions and global.process.versions.node, respectively. Here is the new code:

  console.log(global.process.versions.node)
    var current = typeof nodeVersion === 'undefined'
        ? global.process.versions && global.process.versions.node
        : nodeVersion;