gpt4 book ai didi

node.js - 无法在 Heroku 中推送一些引用

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:25 24 4
gpt4 key购买 nike

`我尝试将我的 Web 应用程序推送到 Heroku,但它给了我这个错误。我搜索了类似的问题,但它对我没有帮助。我以前这样做过并且有效,但是当我尝试再次这样做时却失败了,我不知道为什么。

如何解决此错误?

PS D:\react application> git push heroku master
Enumerating objects: 125, done.
Counting objects: 100% (125/125), done.
Delta compression using up to 4 threads
Compressing objects: 100% (116/116), done.
Writing objects: 100% (125/125), 2.56 MiB | 31.00 KiB/s, done.
Total 125 (delta 29), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Build failed
remote: ! Two different lockfiles found: package-lock.json and yarn.lock
remote:
remote: Both npm and yarn have created lockfiles for this application,
remote: but only one can be used to install dependencies. Installing
remote: dependencies using the wrong package manager can result in missing
remote: packages or subtle bugs in production.
remote:
remote: - To use npm to install your application's dependencies please delete
remote: the yarn.lock file.
remote:
remote: $ git rm yarn.lock
remote:
remote: - To use yarn to install your application's dependences please delete
remote: the package-lock.json file.
remote:
remote: $ git rm package-lock.json
remote:
remote: https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-conflicting-lock-files
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to heroku-react-app-3.
remote:
To https://git.heroku.com/heroku-react-app-3.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/heroku-react-app-3.git'

这是我的应用程序代码:

const path = require('path');
const express = require('express');
const app = express();
const publicPath = path.join(__dirname, '..','public');
const port = process.env.PORT || 3000;

app.use(express.static(publicPath));

app.get('*', (req,res) => {
res.sendFile(path.join(publicPath,'index.html'))
});
app.listen(port, () => {
console.log('Server is up');
});

删除yarn.lock后

PS D:\react application> git push heroku master
Enumerating objects: 130, done.
Counting objects: 100% (130/130), done.
Delta compression using up to 4 threads
Compressing objects: 100% (121/121), done.
Writing objects: 100% (130/130), 2.56 MiB | 33.00 KiB/s, done.
Total 130 (delta 32), reused 0 (delta 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): 10.16.0
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 10.16.0...
remote: Downloading and installing node 10.16.0...
remote: Using default npm version: 6.9.0
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > node-sass@4.12.0 install /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e/node_modules/node-sass
remote: > node scripts/install.js
remote:
remote: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.12.0/linux-x64-64_binding.node
remote: Download complete
remote: Binary saved to /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e/node_modules/node-sass/vendor/linux-x64-64/binding.node
remote: Caching binary to /tmp/npmcache.jQpTT/node-sass/4.12.0/linux-x64-64_binding.node
remote:
remote: > core-js@2.6.9 postinstall /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e/node_modules/core-js
remote: > node scripts/postinstall || echo "ignore"
remote:
remote:
remote: > uglifyjs-webpack-plugin@0.4.6 postinstall /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e/node_modules/uglifyjs-webpack-plugin
remote: > node lib/post_install.js
remote:
remote:
remote: > node-sass@4.12.0 postinstall /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e/node_modules/node-sass
remote: > node scripts/build.js
remote:
remote: Binary found at /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e/node_modules/node-sass/vendor/linux-x64-64/binding.node
remote: Testing binary
remote: Binary is fine
remote: added 1139 packages from 774 contributors and audited 16655 packages in 26.036s
remote: found 36 vulnerabilities (31 low, 2 moderate, 3 high)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: -----> Build
remote: Detected both "build" and "heroku-postbuild" scripts
remote: Running heroku-postbuild
remote:
remote: > expensify@1.0.0 heroku-postbuild /tmp/build_fa4b97b82e26e28c8efaef8a02fd356e
remote: > yarn run build:prod
remote:
remote: sh: 1: yarn: not found
remote: npm ERR! file sh
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno ENOENT
remote: npm ERR! syscall spawn
remote: npm ERR! expensify@1.0.0 heroku-postbuild: `yarn run build:prod`
remote: npm ERR! spawn ENOENT
remote: npm ERR!
remote: npm ERR! Failed at the expensify@1.0.0 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.jQpTT/_logs/2019-06-11T22_03_49_679Z-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: 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: Verifying deploy...
remote:
remote: ! Push rejected to heroku-react-app-3.
remote:
To https://git.heroku.com/heroku-react-app-3.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/heroku-react-app-3.git'

我的脚本

  "engines": {
"node":"10.16.0"


},
"scripts": {
"serve": "live-server public/",
"build": "webpack",
"build:dev": "webpack",
"build:prod": "webpack -p --env production",
"dev-server": "webpack-dev-server",
"test": "jest --config=jest.config.json",
"start": "node server/server.js",
"heroku-postbuild": "yarn run build:prod"
}

最佳答案

鉴于问题是您同时拥有 package-lock.json 和yarn.lock

heroku 使用其他服务器来部署您的应用程序,因此需要下载该远程服务器上的依赖项。

由于您有两个依赖项文件,因此heroku无法决定使用哪一个来下载依赖项,因此会出现错误。

删除您不使用的那个(通常是yarn.json),您的应用程序就可以正常运行了。

关于node.js - 无法在 Heroku 中推送一些引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com