Search code examples
javascriptnode.jsversion

ReferenceError: BigInt is not defined at Object


When I am trying to upgrade the dependency of a sub microservice component in my own micro service component, its giving me this errror as:

    ReferenceError: BigInt is not defined at Object.<anonymous> 
    (/usr/src/app/node_modules/kafkajs/src/utils/long.js:314:22)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/src/app/node_modules/kafkajs/src/broker/index.js:1:76)
    at Module._compile (module.js:653:30)

Long.MIN_VALUE = new Long(BigInt('-9223372036854775808'))

What possibly I am doing wrong or any other dependency I need to add? The node version I am using is 14.17.5 and in the travis the build is passing but failing while deployment. The version that they are using for travis configuration for node is 10.24.1. Will version difference cause a problem? What is the real cause?


Solution

  • The node version I am using is 14.17.5 and in the travis the build is passing but failing while deployment. The version that they are using for travis configuration for node is 10.24.1. Will version difference cause a problem?

    Yes, Node.js didn't have¹ BigInt until version v10.4, so v10.24.1 doesn't have BigInt.

    What is the real cause?

    A really out of date Node.js installation. BigInt is relatively new in JavaScript, and older versions of JavaScript engines (like the V8 in Node.js v10.24.1) don't have it. Node.js v10.24.1 is quite old. The current versions of Node.js are v16.13.1 (LTS) and v17.3.0 (non LTS).


    ¹ Which is to say, didn't upgrade to a version of V8 (its JavaScript engine) that had BigInt until v10.4.