【问题标题】:Heroku - Node version not specified in package.json while deploymentHeroku - 部署时未在 package.json 中指定节点版本
【发布时间】:2022-01-09 12:24:14
【问题描述】:

我正在将我的 React 应用程序部署到 Heroku,但在部署时出现此错误。 当我在本地运行代码时,它运行良好。 这是 Heroku 构建日志以供参考。

-----> Building on the Heroku-20 stack
-----> Using buildpack: https://github.com/mars/create-react-app-buildpack
-----> React.js (create-react-app) multi app detected
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
=====> Detected Framework: Multipack
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       
-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 14.x...
       Downloading and installing node 14.18.2...
       Using default npm version: 6.14.15
       
-----> Installing dependencies
       Installing node modules
       npm ERR! bindings not accessible from watchpack-chokidar2:fsevents
       
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.4mm12/_logs/2022-01-09T12_08_27_820Z-debug.log
-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       Some possible problems:
       
       - Node version not specified in package.json
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile React.js (create-react-app) multi app.
 !     Push failed

我检查了 package.json 但没有发现任何错误 这是 Package.json 文件的一部分

{
  "name": "portfolio",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.6.0",
    "axios": "^0.21.1",
    "bootstrap": "^4.5.3",
    "node": "16.x",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-github-calendar": "^2.0.2",
    "react-icons": "^4.2.0",
    "react-parallax-tilt": "^1.4.68",
    "react-particles-js": "^3.4.1",
    "react-pdf": "^5.4.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.1",
    "typewriter-effect": "^2.17.0",
    "web-vitals": "^0.2.4"
  }
}

请告诉我问题出在哪里

【问题讨论】:

  • 提到错误npm ERR! bindings not accessible from watchpack-chokidar2
  • 删除 packages-lock.json 并使用 NodeJS 14 再次运行
  • 注意:Git 与此无关。当您使用 Git 发送提交以便 Heroku 可以对其进行操作时,Git 只是此设置中的一个传输系统。它将提交转发给 Heroku,然后将 Heroku 的错误转发给您。 这些错误无关,也与它们无关。

标签: node.js reactjs heroku


【解决方案1】:

您应该明确要使用哪个版本的节点来运行您的应用,并将以下内容添加到您的 package.json:

  "engines": {
    "node": "14.17.5"
  }

根据您的需要调整值。

【讨论】:

    【解决方案2】:

    删除 packages-lock.json 并再次运行 node js 应用

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 2019-08-25
      • 2020-07-17
      • 2020-01-24
      • 2023-03-26
      • 2016-10-12
      • 2020-07-19
      • 2017-02-08
      • 1970-01-01
      相关资源
      最近更新 更多