尝试将React应用程序部署到heroku时遇到错误

时间:2018-10-30 14:50:27

标签: reactjs react-native heroku deployment

我正在尝试学习如何将react应用程序部署到heroku,但是每次进行测试运行时,我都会不断收到错误消息。

我一直在使用以下命令来创建React应用并将其部署到heroku:

 $ npx create-react-app struttingpeacocks

 $ cd struttingpeacocks

 $ git init

 $ heroku create struttingpeacocksapp --buildpack https://github.com/mars/create-react-app-buildpack.git

 $ git add .

 $ git commit -m "create-react-app"

 $ git push heroku master

但是,当我执行此操作时,以下代码将在结尾处显示一条错误消息:


 $ git push heroku master

 Counting objects: 18, done.

 Delta compression using up to 8 threads.

 Compressing objects: 100% (18/18), done.

 Writing objects: 100% (18/18), 88.11 KiB | 3.26 MiB/s, done.

 Total 18 (delta 0), reused 0 (delta 0)

 remote: Compressing source files... done.

 remote: Building source:

 remote:

 remote: -----> React.js (create-react-app) multi app detected

 remote: -----> Configure create-react-app build environment

 remote:        Using `NODE_ENV=development`

 remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git

 remote: =====> Detected Framework: Multipack

 remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git

 remote: =====> Detected Framework: Node.js

 remote:

 remote: -----> Creating runtime environment

 remote:

 remote:        NPM_CONFIG_LOGLEVEL=error

 remote:        NPM_CONFIG_PRODUCTION=false

 remote:        NODE_ENV=development

 remote:        NODE_MODULES_CACHE=true

 remote:        NODE_VERBOSE=false

 remote:

 remote: -----> Installing binaries

 remote:        engines.node (package.json):  unspecified

 remote:        engines.npm (package.json):   unspecified (use default)

 remote:        engines.yarn (package.json):  unspecified (use default)
 remote:

 remote:        Resolving node version 8.x...

 remote:        Downloading and installing node 8.12.0...

 remote:        Using default npm version: 6.4.1

 remote:        Resolving yarn version 1.x...

 remote:        Downloading and installing yarn (1.12.1)...

 remote:        Installed yarn 1.12.1

 remote:

 remote: -----> Building dependencies

 remote:        Installing node modules (yarn.lock)

 remote:        yarn install v1.12.1

 remote:        [1/4] Resolving packages...

 remote:        error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.

 remote:        info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

 remote:

 remote: -----> Build failed

 remote:

 remote:  !     Outdated Yarn lockfile

 remote:

 remote:        Your application contains a Yarn lockfile (yarn.lock) which does not

 remote:        match the dependencies in package.json. This can happen if you use npm

 remote:        to install or update a dependency instead of Yarn.

 remote:

 remote:        Please run the following command in your application directory and check

 remote:        in the new yarn.lock file:

 remote:

 remote:        $ yarn install

 remote:        $ git add yarn.lock

 remote:        $ git commit -m "Updated Yarn lockfile"

 remote:        $ git push heroku master

 remote:

 remote:        https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-outdated-yarn-lockfile

 remote:

 remote:  !     Push rejected, failed to compile React.js (create-react-app) multi app.

 remote:

 remote:  !     Push failed

 remote: Verifying deploy...

 remote:

 remote: !       Push rejected to struttingpeacocksapp.

 remote:To https://git.heroku.com/struttingpeacocksapp.git

  ! [remote rejected] master -> master (pre-receive hook declined)

 error: failed to push some refs to 'https://git.heroku.com/struttingpeacocksapp.git'

我的package.json是以下代码

 {
   "name": "struttingpeacocks",
   "version": "0.1.0",
   "private": true,
   "dependencies": {
     "react": "^16.6.0",
     "react-dom": "^16.6.0",
     "react-scripts": "2.1.0"
   },
   "scripts": {
     "start": "react-scripts start",
     "build": "react-scripts build",
     "test": "react-scripts test",
     "eject": "react-scripts eject"
   },
   "eslintConfig": {
     "extends": "react-app"
   },
   "browserslist": [
     ">0.2%",
     "not dead",
     "not ie <= 11",
     "not op_mini all"
   ]
 }

我真的可以为此提供一些帮助。任何建议将不胜感激

3 个答案:

答案 0 :(得分:0)

您应该使用以下方法部署应用程序:

$ heroku create face-tech --buildpack mars/create-react-app
$ git add .
$ git commit -am 'some commit message'
$ git push heroku master

https://github.com/mars/create-react-app-buildpack#user-content-commit--deploy-%EF%B8%8F

答案 1 :(得分:0)

您应该安装此软件包。

npm i create-app-react 
   or
yarn add create-app-react 

npx允许您使用软件包,但尚未安装它,因此在部署过程中可能会引起问题。

并将node和npm的版本添加到package.js

`"engines": { "node": "YOUR_VERSION_OF_NODE",
 "npm": "YOUR_VERSION_OF_NPM"}`, 

您可以通过将node -v npm -v放在cmd中找到版本

答案 2 :(得分:-1)

如果您使用的是npm,请删除“ yarn.lock”文件,然后尝试再次推送代码。确保“ yarn.lock”文件不再位于远程,否则错误将再次出现。

希望这会有所帮助。

相关问题