简体   繁体   English

我可以在本地构建,但我的 heroku 构建失败

[英]I can build locally but my heroku build is failing

In my local environment, the build works properly, and the server works well, but in Heroku, the build fails.在我的本地环境中,构建正常,服务器运行良好,但在 Heroku 中,构建失败。

Even 5 days ago, when I did [git push heroku master] with the same code, I succeeded in distributing it was successful.甚至5天前,当我用相同的代码[git push heroku master]时,我也成功分发了它。 I just don't know why.我只是不知道为什么。

My Node Version: v16.14.0我的节点版本:v16.14.0

My npm Version: 8.12.1我的 npm 版本:8.12.1

THis is the message when I run git push heroku master这是我运行 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 fs-capacitor@6.2.0 does not satisfy fs-capacitor@2.0.4
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'

This is my package.json file这是我的 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"
  }
}

I had the exact same issue a few days ago (early June) while deploying my React app on Heroku as well.几天前(6 月初)我在 Heroku 上部署我的 React 应用程序时也遇到了完全相同的问题。 It seems the problem was caused by the node/npm version update.看来问题是由节点/npm 版本更新引起的。 By default, Heroku uses the latest stable version of node and npm as the building engines, but it might lead to conflicting dependencies if you use a previous version of them.默认情况下,Heroku 使用最新的稳定版本的节点和 npm 作为构建引擎,但如果您使用它们的早期版本,可能会导致依赖冲突。

So, if it works completely fine locally but this issue happens while deploying it on Heroku, here is the solution :因此,如果它在本地完全正常工作,但在 Heroku 上部署时发生此问题,则解决方案如下:

Use node --version and npm --version to check out the versions on your local instance, and then add them under engines section in your package.json file, like this (for you it's 16.14.0 and 8.12.1):使用node --versionnpm --version检查本地实例上的版本,然后将它们添加到 package.json 文件的引擎部分下,像这样(对你来说是 16.14.0 和 8.12.1):

"engines": {
    "node": "16.14.0",
    "npm": "8.12.1"
},

then redeploy the app on Heroku. Problem should be fixed.然后在 Heroku 上重新部署该应用程序。问题应该已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM