首页  编辑  

Nodejs项目启动时报错TypeError: X509Certificate is not a constructor

Tags: /Node & JS/   Date Created:

Nodejs项目启动时报错TypeError: X509Certificate is not a constructor的解决方法

在部署和初始化Nodejs项目时,启动项目报错,错误信息如下:

Type-checking in progress...
(node:13204) UnhandledPromiseRejectionWarning: TypeError: X509Certificate is not a constructor
    at Function.init (xxx\node_modules\als-logger\dist\config\als-config.js:87:26)
    at Object.module.exports [as createAlsLogger] (xxx\node_modules\als-logger\dist\create-als-logger.js:13:28)
    at Object.<anonymous> (xxx\node_modules\als-logger\dist\index.js:38:25)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at AlsLogger.log (xxx\node_modules\shsop-core-common-lib\dist\als\als.utils.js:21:21)
    at AlsLogger.info (xxx\node_modules\shsop-core-common-lib\dist\als\als.utils.js:85:21)
    at Function.create (xxx\node_modules\shsop-core-common-lib\dist\main\app.common.factory.js:35:21)
    at bootstrap (xxx\dist\apps\query-service\main.js:9368:64)
    at xxx\dist\apps\query-service\main.js:9373:1
    at xxx\dist\apps\query-service\main.js:9375:3
    at Object.<anonymous> (xxx\dist\apps\query-service\main.js:9377:12)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:13204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

错误代码行:
  1. const x509 = new X509Certificate(xxx.publicKey);

这是版本兼容导致的,AlsLogger需要Nodejs v16.18以上环境。解决方法:升级到Nodejs v16.18及以上版本即可。