ReferenceError: BigInt is not defined at Object

ReferenceError: BigInt is not defined at Object

当我试图在我自己的微服务组件中升级子微服务组件的依赖时,它给我这个错误:

    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'))

我可能做错了什么或我需要添加任何其他依赖项? 我使用的节点版本是 14.17.5 并且在 travis 中构建通过但在部署时失败。他们用于节点的 travis 配置的版本是 10.24.1。版本差异会导致问题吗?真正的原因是什么?

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?

是的,Node.js 在 version v10.4 之前没有¹ BigInt,所以 v10.24.1 没有 BigInt.

What is the real cause?

一个非常过时的 Node.js 安装。 BigInt 在 JavaScript 中相对较新,旧版本的 JavaScript 引擎(如 Node.js v10.24.1 中的 V8)没有它。 Node.js v10.24.1 很旧。 Node.js 的 current versions 是 v16.13.1 (LTS) 和 v17.3.0(非 LTS)。


¹ 也就是说,直到 v10.4 才升级到具有 BigInt 的 V8 版本(其 JavaScript 引擎)。