You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node 14升级至20.14后执行yarn test报SIGSEGV错误求助

Node 20.14 + Mac M3芯片执行yarn test触发SIGSEGV错误排查方案

我使用Mac M3芯片,将Node版本从14升级至20.14,同时升级了以下三个依赖:

  • Couchbase:3.1.3 → 4.2.5
  • elastic-apm-node:3.9.0 → 4.7.1
  • mongodb:3.6.4 → 6.8.0

执行yarn test时触发错误:error Command failed with signal "SIGSEGV",但该命令在Node 14环境下可正常运行。

我的package.json内容如下:

{
  "main": "server.js",
  "license": "MIT",
  "dependencies": {
    "@google-cloud/storage": "5.8.4",
    "@sendgrid/mail": "^7.4.2",
    "adm-zip": "^0.5.9",
    "axios": "0.21.4",
    "body-parser": "1.19.0",
    "bunyan": "1.8.15",
    "consul": "^0.40.0",
    "cors": "2.8.5",
    "couchbase": "4.2.5",
    "crypto-random-int": "1.0.1",
    "csv-stream": "^0.2.0",
    "csv-writer": "^1.6.0",
    "csvtojson": "2.0.10",
    "dotenv": "8.2.0",
    "dotenv-expand": "5.1.0",
    "elastic-apm-node": "4.7.1",
    "express": "4.17.3",
    "express-requests-logger": "4.0.0",
    "find-config": "1.0.0",
    "firebase": "8.2.3",
    "firebase-admin": "9.4.2",
    "jest": "^29.5.0",
    "jest-html-reporters": "^3.1.4",
    "joi": "^17.6.0",
    "json2csv": "5.0.6",
    "jwt-decode": "3.0.0-beta.2",
    "kafkajs": "^1.15.0",
    "lodash": "^4.17.21",
    "memory-cache": "0.2.0",
    "moment": "2.29.4",
    "mongodb": "6.8.0",
    "multer": "1.4.2",
    "nodemon": "2.0.4",
    "objects-to-csv": "1.3.6",
    "serialize-error": "8.0.1",
    "through2": "^4.0.2",
    "unirest": "^0.6.0"
  },
  "scripts": {
    "test": "jest --runInBand",
    "start": "NODE_ENV=development nodemon server.js",
    "start:local": "NODE_ENV=local nodemon server.js",
    "start:production": "node server.js"
  },
  "devDependencies": {
    "jest": "^29.5.0",
    "supertest": "^6.3.3"
  }
}

已提供错误截图,以下是具体排查和解决步骤:

1. 修复原生依赖编译问题

SIGSEGV错误大多和原生编译模块的兼容性有关,M3的arm64架构可能导致部分依赖编译异常:

  • 删除node_modules文件夹和yarn.lock文件,执行yarn install --force强制重新安装并编译所有依赖;
  • 确认Couchbase、mongodb这类带原生模块的依赖版本是否明确支持Node 20 + Apple Silicon,可查看对应依赖的官方Release Notes或GitHub文档。

2. 排查elastic-apm-node兼容性

临时注释代码中elastic-apm-node的初始化逻辑,重新执行yarn test:

  • 如果错误消失,说明是APM模块的问题,尝试降级到4.x系列的中间版本(比如4.5.0),或查看官方文档的Node版本兼容说明;
  • 确保elastic-apm-node的配置项适配Node 20的新特性。

3. 升级Jest版本

当前Jest 29.5.0对Node 20的支持存在不完善,升级到29.x最新版本:

yarn add jest@^29.7.0 jest-html-reporters@latest --dev

同时检查jest.config.js(如果存在),移除过时的配置项。

4. 定位触发错误的测试用例

通过单个测试文件运行来缩小范围:

yarn test path/to/your-test-file.js

找到具体触发SIGSEGV的测试用例后,检查是否涉及Couchbase/mongodb的连接、查询等操作,针对性调整代码适配新依赖版本的API变化。

5. 同步升级其他旧依赖

部分旧依赖(如@google-cloud/storage 5.8.4)可能不支持Node 20,查看其官方文档确认兼容版本,同步升级到支持Node 20的版本。

内容的提问来源于stack exchange,提问作者Laksh Mishra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 05:39:57