如何解决MERN Stack - 在 Heroku 上部署时收到错误
我开发了一个 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"
},
解决方法
快速提问,您是否尝试将后端和前端与 heroku 一起部署?
过去我使用 heroku 部署后端,使用 netlify 部署前端
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。