簡體   English   中英

我可以在本地構建,但我的 heroku 構建失敗

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

在我的本地環境中,構建正常,服務器運行良好,但在 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 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'

這是我的 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"
  }
}

幾天前(6 月初)我在 Heroku 上部署我的 React 應用程序時也遇到了完全相同的問題。 看來問題是由節點/npm 版本更新引起的。 默認情況下,Heroku 使用最新的穩定版本的節點和 npm 作為構建引擎,但如果您使用它們的早期版本,可能會導致依賴沖突。

因此,如果它在本地完全正常工作,但在 Heroku 上部署時發生此問題,則解決方案如下:

使用node --versionnpm --version檢查本地實例上的版本,然后將它們添加到 package.json 文件的引擎部分下,像這樣(對你來說是 16.14.0 和 8.12.1):

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

然后在 Heroku 上重新部署該應用程序。問題應該已解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM