很难将我的 MERN 堆栈应用程序部署到 Heroku

时间:2021-01-26 16:57:31

标签: node.js reactjs heroku mern heroku-cli

我一直在关注 brad traversy 的托管全栈 mern 应用程序的指南,

但是在我运行 git push heroku master 后,我不断收到此错误:

$ git push heroku master
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 8 threads
Compressing objects: 100% (36/36), done.
Writing objects: 100% (39/39), 427.21 KiB | 8.06 MiB/s, done.
Total 39 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 12.x...
remote:        Downloading and installing node 12.20.1...
remote:        Using default npm version: 6.14.10
remote:
remote: -----> Installing dependencies
remote:        Installing node modules
remote:
remote:        > nodemon@2.0.6 postinstall /tmp/build_a03a558d/node_modules/node
mon
remote:        > node bin/postinstall || exit 0
remote:
remote:        Love nodemon? You can now support the project via the open collec
tive:
remote:         > https://opencollective.com/nodemon/donate
remote:
remote:        added 296 packages in 4.302s
remote:
remote: -----> Build
remote:        Detected both "build" and "heroku-postbuild" scripts
remote:        Running heroku-postbuild
remote:
remote:        > server@1.0.0 heroku-postbuild /tmp/build_a03a558d
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && np
m run build --prefix frontend
remote:
remote:        up to date in 0.241s
remote:        found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_a03a558d/frontend/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_a03a
558d/frontend/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.ZT0se/_logs/2021-01-26T16_52_50_692Z-debug.lo
g
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! server@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm
 install --prefix frontend && npm run build --prefix frontend`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the server@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additi
onal logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.ZT0se/_logs/2021-01-26T16_52_50_713Z-debug.lo
g
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common is
sues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploy
s
remote:
remote:        Some possible problems:
remote:
remote:        - Node version not specified in package.json
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying
-a-node-js-version
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to fathomless-thicket-55387.
remote:
To https://git.heroku.com/fathomless-thicket-55387.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/fathomless-thicket-55
387.git'

我不知道为什么会收到这些错误消息... 远程:npm 错误!路径/tmp/build_a03a558d/frontend/package.json 远程:npm 错误!错误号 -2 远程:npm 错误! enoent ENOENT: 没有那个文件或目录,打开'/tmp/build_a03a 558d/frontend/package.json'

1 个答案:

答案 0 :(得分:0)

你需要检查

  1. 您是否在 win32c.xlTopCount 文件夹中有 package.json 文件。您可以在 git 中查看它是否存在。可能会在 gitignore 中提到。

  2. 您的 frontend 是否从与文件夹 {{1} 处于同一级别的 package.json(与 heroku-postbuild 文件夹中的 package.json 文件不同)运行}.像这样:

    • package.json
    • /前端