在Heroku中部署MERN堆栈应用程序时出现问题



这个问题的解决方案是什么?我在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

如果是heroku postbuild问题,则首先运行

npm run build

在客户端文件夹(前端应用程序(中的本地系统中,如果react应用程序中缺少一些依赖项,它将抛出错误

如果build命令仅成功,则删除node_modules和package-lock.json文件,然后运行

npm install

最新更新