在我的本地环境中,构建工作正常,服务器运行良好,但在 Heroku 中,构建失败。
甚至5天前,当我使用相同的代码执行[git push heroku master]时,我成功地分发了它。 我只是不知道为什么。
我的节点版本:v16.14.0
我的 npm 版本:8.12.1
这是我运行 git push heroku master 时出现的消息
Enumerating objects: 157, done.
Counting objects: 100% (157/157), done.
Delta compression using up to 8 threads
Compressing objects: 100% (132/132), done.
Writing objects: 100% (139/139), 34.60 KiB | 1.65 MiB/s, done.
Total 139 (delta 64), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/nodejs
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): 16.x
remote: engines.npm (package.json): 8.x
remote:
remote: Resolving node version 16.x...
remote: Downloading and installing node 16.15.1...
remote: Bootstrapping npm 8.x (replacing 8.11.0)...
remote: npm 8.12.1 installed
remote:
remote: -----> Restoring cache
remote: Cached directories were not restored due to a change in version of node, npm, yarn or stack
remote: Module installation may take longer for this build
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote: npm ERR! code EUSAGE
remote: npm ERR!
remote: npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
remote: npm ERR!
remote: npm ERR! Invalid: lock file's <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc9a8fd19f9d8c9d9f9588938ebccad2ced2cc" rel="noreferrer noopener nofollow">[email protected]</a> does not satisfy <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c6a7f216f6d7c6d6f6578637e4c3e223c2238" rel="noreferrer noopener nofollow">[email protected]</a>
remote: npm ERR!
remote: npm ERR! Clean install a project
remote: npm ERR!
remote: npm ERR! Usage:
remote: npm ERR! npm ci
remote: npm ERR!
remote: npm ERR! Options:
remote: npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
remote: npm ERR! [--script-shell <script-shell>]
remote: npm ERR!
remote: npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
remote: npm ERR!
remote: npm ERR! Run "npm help ci" for more info
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.eCi5I/_logs/2022-06-10T15_29_27_934Z-debug-0.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: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 1c50da0c5e766307c0583b04cc9e990d1b19088b
remote: !
remote: ! We have detected that you have triggered a build from source code with version 1c50da0c5e766307c0583b04cc9e990d1b19088b
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to evencafe-backend.
remote:
To https://git.heroku.com/evencafe-backend.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/evencafe-backend.git'
这是我的 package.json 文件
{
"name": "evencafe-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"preinstall": "npx npm-force-resolutions",
"dev": "nodemon --exec babel-node src/server.js",
"migrate": "npx prisma migrate dev",
"studio": "npx prisma studio",
"build": "babel src --out-dir build",
"start": "node build/server"
},
"repository": {
"type": "git",
"url": "git+https://github.com/evencoding/evencafe-backend.git"
},
"author": "Even Coding",
"license": "MIT",
"bugs": {
"url": "https://github.com/evencoding/evencafe-backend/issues"
},
"homepage": "https://github.com/evencoding/evencafe-backend#readme",
"dependencies": {
"@babel/cli": "^7.17.10",
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/runtime": "^7.18.3",
"@graphql-tools/load-files": "^6.5.3",
"@graphql-tools/merge": "^8.2.10",
"@graphql-tools/schema": "^8.3.10",
"@prisma/client": "^3.8.1",
"apollo-server": "^2.25.2",
"apollo-server-express": "^2.25.2",
"aws-sdk": "^2.1144.0",
"bcrypt": "^5.0.1",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"graphql": "^15.8.0",
"jsonwebtoken": "^8.5.1",
"fs-capacitor": "6.2.0"
},
"devDependencies": {
"@babel/core": "^7.16.10",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.10",
"nodemon": "^2.0.16",
"prisma": "^3.14.0"
},
"resolutions": {
"fs-capacitor": "6.2.0",
"graphql-upload": "^11.0.0"
}
}
最佳答案
几天前(六月初)我在 Heroku 上部署 React 应用程序时也遇到了完全相同的问题。看来问题是由node/npm版本更新引起的。默认情况下,Heroku 使用最新稳定版本的 Node 和 npm 作为构建引擎,但如果您使用它们的早期版本,可能会导致依赖项冲突。
所以,如果它在本地工作完全正常,但在 Heroku 上部署时出现此问题,解决方案如下:
使用 node --version
和 npm --version
查看本地实例上的版本,然后将它们添加到 package.json 文件的引擎部分下,像这样(对于您来说是 16.14.0 和 8.12.1):
"engines": {
"node": "16.14.0",
"npm": "8.12.1"
},
然后在 Heroku 上重新部署应用程序。问题应该得到解决。
关于javascript - 我可以在本地构建,但我的 heroku 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72576874/