MERN Stack - 在 Heroku 上部署时收到错误

时间:2021-06-02 11:50:22

标签: heroku mern

我开发了一个 MERN 堆栈应用程序并创建了 React 版本。在地址部署之前构建工作

http://localhost:3304/

但是,当我尝试部署它时,出现以下错误

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       
-----> Installing binaries
       engines.node (package.json):  14.17.0
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 14.17.0...
       Downloading and installing node 14.17.0...
       Using default npm version: 6.14.13
       
-----> Installing dependencies
       Installing node modules
       added 79 packages in 1.784s
       
-----> Build
       Running heroku-postbuild
       
       > backend@1.0.0 heroku-postbuild /tmp/build_b4cd03b2
       > NPM_CONFIG_PRODUCTION=false npm install npm && run ../build
       
       + npm@7.15.1
       added 254 packages from 921 contributors and audited 333 packages in 8.161s
       
       13 packages are looking for funding
         run `npm fund` for details
       
       found 0 vulnerabilities
       
sh: 1: run: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! backend@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install npm && run ../build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the backend@1.0.0 heroku-postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.AcJvb/_logs/2021-06-02T08_22_03_806Z-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
       
       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

package.json 文件添加了以下几行。作为客户端代码的构建和作为服务器代码的后端被放置在两个目录中。

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon app.js",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install npm && run ../build"
  },

1 个答案:

答案 0 :(得分:0)

快速提问,您是否尝试将后端和前端与 heroku 一起部署?

过去我使用 heroku 部署后端,使用 netlify 部署前端