node.js - 很难将我的 MERN 堆栈应用程序部署到 Heroku
问题描述
我一直在关注 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 ERR!路径 /tmp/build_a03a558d/frontend/package.json 远程:npm ERR!errno -2 远程:npm ERR!enoent ENOENT:没有这样的文件或目录,打开'/tmp/build_a03a 558d/frontend/package.json'
解决方案
你需要检查
文件夹中是否有
package.json
文件frontend
。您可以在 git 中查看它是否存在。可能会在 gitignore 中提到。您是否
heroku-postbuild
从与 folder 处于同一级别的package.json (与package.json
文件夹中的文件不同)运行。像这样:frontend
frontend
- 包.json
- /前端
推荐阅读
- macos - 谁能帮我解决第 114 行的 apache 错误?
- c# - 如何在 C# 中比较两个 GUID 值(一个来自数据库,一个在“if”语句中手动编码)?
- linux - 将 vim 配色方案应用于 sudo root 但不影响其他用户 sudo
- websocket - 使用 wscat 测试(学习)websockify,可以监听但发送任何内容都会导致断开连接
- godot - 未在继承类中声明的方法
- javascript - 派生一个子进程并将反应组件作为参数传递
- python - if 语句在 AWS lambda 控制台中不起作用
- node.js - Haraka 身体解析器并添加警告
- html - 我的音频在 Edge 和 Chrome 中都没有下载选项
- r - 材料开关在闪亮时无法按预期工作