Не удалось нажать некоторые ссылки в Heroku - PullRequest
0 голосов
/ 12 июня 2019

`Я пытался перенести свое веб-приложение в 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 голосов
/ 12 июня 2019

Поскольку проблема в том, что у вас есть и package-lock.json, и yarn.lock

Heroku использует другие серверы для развертывания вашего приложения, поэтому ему нужно загрузить зависимости на этом удаленном сервере.

Поскольку у вас есть два файла зависимостей, поэтому heroku не может решить, какой из них использовать для загрузки зависимостей, отсюда и ошибка.

Удалите тот файл, который вы не используете (обычно yarn.json), и свое приложение.будет хорошо идти.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...