MERN应用程序在部署到Heroku时无法运行“ heroku-postbuild”脚本

尼古拉斯·布拉胡希亚克

一切正常,直到我尝试将应用程序部署到Heroku。登录后,这些是我运行以部署应用程序(和响应)的终端命令:

heroku login
heroku: Press any key to open up the browser to login or q to exit: 
Logging in... done
Logged in as #hidden

heroku create
Creating app... done, ⬢ lower-donair-61893
https://lower-donair-61893.herokuapp.com/ | https://git.heroku.com/lower-donair-61893.git

git init
Initialized empty Git repository in #hidden

heroku git:remote -a lower-donair-61893

git add .
warning: adding embedded git repository: client
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached client
hint: 
hint: See "git help submodule" for more information.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory

git commit -am "make it better"
[master (root-commit) cdaf621] make it better
 13 files changed, 2518 insertions(+)
 create mode 100644 .gitignore
 create mode 160000 client
 create mode 100644 config/default.json
 create mode 100644 models/Comment.js
 create mode 100644 models/Post.js
 create mode 100644 models/User.js
 create mode 100644 package-lock.json
 create mode 100644 package.json
 create mode 100644 routes/api/auth.js
 create mode 100644 routes/api/posts.js
 create mode 100644 routes/api/users.js
 create mode 100644 server.js

当我运行最后一个命令时,“乐趣”开始:

git push heroku master
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (15/15), done.
Writing objects: 100% (19/19), 28.99 KiB | 1.61 MiB/s, done.
Total 19 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
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.18.2...
remote:        Using default npm version: 6.14.5
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        
remote:        > [email protected] postinstall /tmp/build_01ff90de74651f20444f369d014096d8/node_modules/nodemon
remote:        > node bin/postinstall || exit 0
remote:
remote:        Love nodemon? You can now support the project via the open collective:
remote:         > https://opencollective.com/nodemon/donate
remote:
remote:        added 267 packages from 151 contributors and audited 268 packages in 9.402s
remote:        
remote:        12 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 0 vulnerabilities
remote:
remote:        
remote: -----> Build
remote:        Running heroku-postbuild
remote:        
remote:        > heroku-postbuild /tmp/build_01ff90de74651f20444f369d014096d8
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:        up to date in 0.219s
remote:        found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_01ff90de74651f20444f369d014096d8/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_01ff90de74651f20444f369d014096d8/client/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.0iNHH/_logs/2020-07-01T13_46_53_504Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.0iNHH/_logs/2020-07-01T13_46_53_520Z-debug.log
remote:
remote: -----> Build failed
remote:        
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
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 lower-donair-61893.
remote:
To https://git.heroku.com/lower-donair-61893.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/lower-donair-61893.git'

因此这是一个ENOENT,但我搜索了部署到Heroku的其他MERN应用,并找到了这个视频:https : //www.youtube.com/watch?v= 71wSzpLyW9k & list = PLillGF-RfqbbiTGgA77tGO426V3hRF9iE & index =8,其中他使用了相同的像我一样编写代码。而且我的应用是他系列的“延续”,因此文件结构,脚本等是完全相同的(这意味着,如果您导航到视频的desc,您可以看到指向github repo的链接,该链接少了很多) ,但克隆了package.json等密钥文件)。

这是我要运行的postbuild脚本:

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"

这是我的文件结构的屏幕截图:文件结构

我过去4个小时一直在寻找答案,却一无所获。错误消息指出了此路径,但我无法真正找到它来查看完整的日志。

/tmp/npmcache.0iNHH/_logs/2020-07-01T13_46_53_504Z-debug.log 

请,如果您需要了解更多信息,请告诉我,我会很乐意提供您所需的内容-现在,我将复制所有package.json文件(服务器和客户端)中的代码:

服务器一:

{
    "name": "#hidden",
    "version": "1.0.0",
    "description": "#hidden",
    "main": "server.js",
    "scripts": {
        "client-install": "npm install --prefix client",
        "start": "node server",
        "server": "nodemon server",
        "client": "npm start --prefix client",
        "dev": "concurrently \"npm run server\" \"npm run client\"",
        "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
    },
    "keywords": [
       #hidden
    ],
    "author": "#hidden",
    "license": "ISC",
    "dependencies": {
        "bcryptjs": "^2.4.3",
        "concurrently": "^5.2.0",
        "config": "^3.3.1",
        "express": "^4.17.1",
        "jsonwebtoken": "^8.5.1",
        "mongoose": "^5.9.19"
    },
    "devDependencies": {
        "nodemon": "^2.0.4"
    }
}

客户一:

{
    "name": "client",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.3.2",
        "@testing-library/user-event": "^7.1.2",
        "axios": "^0.19.2",
        "bootstrap": "^4.5.0",
        "moment": "^2.27.0",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-moment": "^0.9.7",
        "react-redux": "^7.2.0",
        "react-router-dom": "^5.2.0",
        "react-router-redux": "^4.0.8",
        "react-scripts": "3.4.1",
        "react-transition-group": "^4.4.1",
        "reactstrap": "^8.4.1",
        "redux": "^4.0.5",
        "redux-thunk": "^2.3.0"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    },
    "proxy": "http://localhost:5000"
}

提前致谢!

尼古拉斯·布拉胡希亚克

我设法解决了这个问题,并通过删除客户端文件夹中的所有默认gitignore异常成功部署了应用程序。我不知道为什么,但是其中包含“ / build”。我的最终客户端gitignore文件仅包括:

/node_modules

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

缺少脚本:将应用程序部署到Heroku时,启动和应用程序崩溃

Mern Stack应用程序在Heroku Local上运行但在部署时无法在线运行

Rails应用程序在本地运行,但在部署到Heroku时无法运行

MERN应用程序部署到heroku,空白页

部署到Heroku时Heroku应用程序错误

在Heroku上从Java / Kotlin应用程序运行Python脚本

无法将我的 symfony 应用程序部署到 heroku

无法将Spring Boot应用程序部署到heroku

无法将示例GOLang应用程序部署到Heroku

我的应用程序无法部署到 heroku

无法将 Laravel 应用程序部署到 Heroku

无法将应用程序部署到heroku

无法将 rails 应用程序部署到 heroku

将Angular应用程序部署到Heroku时出错

部署到heroku时出现应用程序错误

将 Django 应用程序部署到 Heroku 时出错

使用Docker将Django应用程序部署到heroku时在哪里运行collectstatic?

在将 Angular 应用程序部署到 heroku 和运行 ng serve 时出错?

部署到Heroku应用程序错误

将Mern应用程序部署到heroku之后的路由问题

将MERN应用程序部署到Heroku后,缺少React组件

我将MERN应用程序部署到Heroku出了什么问题?

如何将MERN堆栈应用程序部署到GitHub和Heroku?

尝试将Django应用程序部署到Heroku时出现“无法连接('0.0.0.0',5000)”

将Rails应用程序部署到Heroku时出现“无法加载此类文件”错误

无法使用 heroku local 将 Django 应用程序部署到 heroku

将我的Rails应用程序部署到heroku时出现应用程序错误

应用程序与 buildpack 不兼容:将 django 应用程序部署到 heroku 时出错

Heroku 上的 MERN 应用程序