无法在Heroku中推送一些裁判

时间:2019-06-11 21:27:46

标签: node.js heroku

`我试图将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"
  }

1 个答案:

答案 0 :(得分:0)

给出的问题是您同时拥有package-lock.json和yarn.lock

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

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

删除不使用的应用程序(通常是yarn.json),您的应用将很不错。