node.js - Heroku - 部署时 package.json 中未指定 Node 版本

标签 node.js reactjs heroku

我正在将 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"
  }
}

请告诉我问题出在哪里

最佳答案

您应该精确确定要使用哪个版本的 Node 来运行应用程序,并将以下内容添加到 package.json 中:

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

根据您的需要调整该值。

关于node.js - Heroku - 部署时 package.json 中未指定 Node 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70641222/

相关文章:

windows - Bower 安装包 EPERM 重命名错误

wordpress - git pre-receive hook 拒绝 heroku

javascript - 是否可以使用 Nodejs 和 Socket.io 更新页面的单个部分?

javascript - 无法将两个 api 调用链接到 mongo 数据库

node.js - GraphQL:react-apollo 客户端覆盖数组元素

javascript - React 组件设置其子组件的 onClick ...如何使其适用于所有类型的子组件

reactjs - react-virtualized ,在哪里调用 forceUpdateGrid 更新表数据?

heroku - 是否将Heroku高级PostgreSQL等级降级为标准?

heroku - 如何使用 Nuxt.JS 应用程序访问 Heroku 环境变量

node.js - 文件上传后 jQuery 的 Ajax 回调未触发