这个问题的解决方案是什么?尝试在 Heroku 中部署 MERN 堆栈时出现此错误。我所做的是:我配置了 MONGO_URI、PORT 等。在 Github 中推送所有工作代码仍然出现此错误。我应该怎么做才能成功部署这个应用程序?我尝试通过阅读 Heroku 文档和观看 youtube 教程来部署该应用程序。
-----> 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.16.1
engines.npm (package.json): 6.14.12
Resolving node version 14.16.1...
Downloading and installing node 14.16.1...
npm 6.14.12 already installed with node
-----> Installing dependencies
Installing node modules
> nodemon@2.0.7 postinstall /tmp/build_5044977d/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate
> bcrypt@5.0.1 install /tmp/build_5044977d/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
[bcrypt] Success: "/tmp/build_5044977d/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
added 365 packages in 9.194s
-----> Build
Running heroku-postbuild
> car-app@1.0.0 heroku-postbuild /tmp/build_5044977d
> NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend
up to date in 0.234s
found 0 vulnerabilities
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /tmp/build_5044977d/frontend/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_5044977d/frontend/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.GU88T/_logs/2021-07-02T10_17_10_423Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 254
npm ERR! car-app@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend`
npm ERR! Exit status 254
npm ERR!
npm ERR! Failed at the car-app@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.GU88T/_logs/2021-07-02T10_17_10_446Z-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
答案 0 :(得分:0)
如果是heroku postbuild问题,那么首先运行
npm run build
在客户端文件夹(前端应用程序)内的本地系统中,如果您的反应应用程序中缺少某些依赖项,它将引发错误,
如果构建命令成功,则删除 node_modules 和 package-lock.json 文件,然后运行
npm install