推送到 Heroku 被拒绝,破坏 package.json
Posted
技术标签:
【中文标题】推送到 Heroku 被拒绝,破坏 package.json【英文标题】:Push to Heroku being rejected, breaking in package.json 【发布时间】:2021-03-26 12:26:35 【问题描述】:尝试推送到 Heroku 时,我不断收到此错误:
remote: ! Push rejected to infinite-cove-33100.
remote:
To https://git.heroku.com/infinite-cove-33100.git
! [remote rejected] master -> master (pre-receive hook declined)
它总是在:
remote: > mern_ecommerce@1.0.0 heroku-postbuild /tmp/build_43ebd568
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend
remote:
remote: up to date in 0.284s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_43ebd568/frontend/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_43ebd568/frontend/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
package.json 中的所有版本都是准确的,.gitignore 中需要的所有内容都在那里,包括 node_modules,heroku 具有正确的 buildpack,并且所有内容都已添加并使用 git 提交。
我经历过:https://devcenter.heroku.com/articles/troubleshooting-node-deploys 还没有解决方案。
这是它不断破坏的 package.json:
"name": "mern_ecommerce",
"version": "1.0.0",
"engines": "node": "14.15.1",
"description": "MERN shopping cart app",
"main": "server.js",
"type": "module",
"scripts":
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"data:import": "node backend/seeder",
"data:destroy": "node backend/seeder -d",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
,
"author": "John Doe",
"license": "ISC",
"dependencies":
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"dotenv": "^8.2.0",
"e
xpress": "^4.17.1",
"express-async-handler": "^1.1.4",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.4",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"node": "^14.15.1",
"react": "^17.0.1",
"react-scripts": "^4.0.1"
,
"devDependencies":
"concurrently": "^5.3.0",
"nodemon": "^2.0.6"
【问题讨论】:
【参考方案1】:我不知道最初的问题是什么,但我能够通过链接 github 使用 Heroku 站点上的部署选项卡进行部署...不是我想要的方式,但它可以工作。
【讨论】:
【参考方案2】:对于任何在构建 Heroku 时遇到问题的人,可能值得通过运行 npm install -g npx
安装 npx 并通过运行 npx @heroku/update-node-build-script
让它检查 package.json 文件的内容。
另见:https://www.npmjs.com/package/@heroku/update-node-build-script
人工检查:https://help.heroku.com/P5IMU3MP/heroku-node-js-build-script-change-faq
【讨论】:
【参考方案3】:尝试运行npm install
有时会发生这种情况,因为您手动更新了 package.json,这不会影响 package-lock.json,因此它与远程不同,因此无法部署
【讨论】:
以上是关于推送到 Heroku 被拒绝,破坏 package.json的主要内容,如果未能解决你的问题,请参考以下文章
Heroku 推送被拒绝,无法通过 Bundler 安装 gem
Heroku/Rails/Devise:你想要的改变被拒绝了