【问题标题】:Can not deploy nodejs to heroku via heroku-cli and github无法通过 heroku-cli 和 github 将 nodejs 部署到 heroku
【发布时间】:2026-02-03 20:30:01
【问题描述】:

我在将我的 nodejs 应用程序部署到 Heroku 时遇到问题。我尝试直接 git push(heroku cli),也尝试从 github deploy,但都失败了。我得到了这里的日志:

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Node.js app detected
jq: error (at <stdin>:19): Cannot index string with string "iojs"
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

我试图检查 devdependents 是否是罪魁祸首,然后尝试更改 devdependents 包并删除所有“可能”导致失败的 node_modules 文件,但重试后,我仍然面临这个问题。我还尝试将引擎从 17.x 更改为 16.x,但仍然存在。

也许有人可以给我一个线索?

下面的 package.json 我有:

{
  "name": "coupling",
  "version": "1.0.0",
  "engines": "17.x",
  "description": "",
  "main": "server.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@vercel/node": "^1.12.1",
    "csv-parser": "^3.0.0",
    "express": "4.17.2",
    "ws": "^8.4.2"
  }
}

【问题讨论】:

    标签: node.js heroku deployment


    【解决方案1】:

    您的engines 部分无效:

      "engines": "17.x",
    

    Its value should be an object, not a string。试试这个:

      "engines": {
        "node": "17.x"
      }
    

    【讨论】:

    • 我已编辑,但问题仍然存在。检查 csv-parser 有需要 iojs 的文本。所以我使用另一个模块并使用来自 nodejs-getting-started 的模板,我成功部署了。
    • @fadlim,具体内容取决于您的具体需求。我对你的申请一无所知,所以你可能不得不这样做。关键是engines 需要是一个object。这解决了您在上面遇到的问题。如果您想使用 io.js you can,但这与您提出的问题无关。 (错误中提到了iojs,但这只是因为它恰好是第一个尝试的引擎字符串。问题是jq 无法将"17.x" 处理为JSON 字符串。)