部署React App进行Netlify时构建失败

时间:2018-10-13 03:14:58

标签: deployment create-react-app netlify

我使用create-react-app创建了一个React应用。 现在,我试图在netlify上部署它,但收到错误消息。

8:16:39 AM: Build ready to start
8:16:40 AM: build-image version: 42bca793ccd33055023c56c4ca8510463a56d317
8:16:40 AM: buildbot version: 6bab8b64bbd90091082af19fedf16bf73d502e5e
8:16:40 AM: Fetching cached dependencies
8:16:40 AM: Starting to download cache of 254.7KB
8:16:40 AM: Finished downloading cache in 97.851508ms
8:16:40 AM: Starting to extract cache
8:16:40 AM: Failed to fetch cache, continuing with build
8:16:40 AM: Starting to prepare the repo for build
8:16:41 AM: No cached dependencies found. Cloning fresh repo
8:16:41 AM: git clone git@bitbucket.org:ampcomeiot/iot-web-app
8:16:43 AM: Preparing Git Reference refs/heads/master
8:16:44 AM: Starting build script
8:16:44 AM: Installing dependencies
8:16:45 AM: Downloading and installing node v8.12.0...
8:16:45 AM: Downloading https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x64.tar.xz...
8:16:45 AM: 0.6
8:16:45 AM: %
8:16:45 AM: 
###
8:16:45 AM:                                       4.8%
8:16:45 AM: 
#####################################
8:16:45 AM:                                      52.0%
8:16:45 AM: 
####################################
8:16:45 AM: #################################### 100.0%
8:16:45 AM: Computing checksum with sha256sum
8:16:46 AM: Checksums matched!
8:16:48 AM: Now using node v8.12.0 (npm v6.4.1)
8:16:48 AM: Attempting ruby version 2.3.6, read from environment
8:16:49 AM: Using ruby version 2.3.6
8:16:49 AM: Using PHP version 5.6
8:16:49 AM: Started restoring cached node modules
8:16:49 AM: Finished restoring cached node modules
8:16:49 AM: Started restoring cached yarn cache
8:16:49 AM: Finished restoring cached yarn cache
8:16:49 AM: Installing yarn at version 1.3.2
8:16:49 AM: Installing Yarn!
8:16:49 AM: > Downloading tarball...
8:16:49 AM: [1/2]: https://yarnpkg.com/downloads/1.3.2/yarn-v1.3.2.tar.gz --> /tmp/yarn.tar.gz.x4SAX8ROjQ
8:16:49 AM:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
8:16:49 AM:                                  Dload  Upload   Total   Spent    Left  Speed
8:16:49 AM: 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
8:16:49 AM: 
100    91  100    91    0     0    470
8:16:49 AM:      0 --:--:-- --:--:-- --:--:--   471
8:16:49 AM: 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--
8:16:49 AM:      0
  0     0    0   608    0     0   1456      0 --:--:-- --:--:-- --:--:-- 60800
8:16:50 AM: 
100  865k  100  865k    0     0   897k      0 --:--:-- --:--:-- --:--:--  897k
8:16:50 AM: [2/2]: https://yarnpkg.com/downloads/1.3.2/yarn-v1.3.2.tar.gz.asc --> /tmp/yarn.tar.gz.x4SAX8ROjQ.asc
8:16:50 AM: 
100    95  100    95    0     0   1891
8:16:50 AM:    0 --:--:-- --:--:-- --:--:--  1891
8:16:50 AM: 
  0     0    0   612    0     0   3928      0 --:--:-- --:--:-- --:--:--  3928
8:16:50 AM: 
100  1027  100  1027    0     0   4858      0 --:--:-
8:16:50 AM: - --:--:-- --:--:--  4858
8:16:50 AM: > Verifying integrity...
8:16:50 AM: gpg: Signature made Thu 02 Nov 2017 04:44:10 PM UTC using RSA key ID FD2497F5
8:16:50 AM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
8:16:50 AM: gpg: WARNING: This key is not certified with a trusted signature!
8:16:50 AM: gpg:          There is no indication that the signature belongs to the owner.
8:16:50 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
8:16:50 AM:      Subkey fingerprint: 6A01 0C51 6600 6599 AA17  F081 46C2 130D FD24 97F5
8:16:50 AM: > GPG signature looks good
8:16:50 AM: > Extracting to ~/.yarn...
8:16:50 AM: > Adding to $PATH...
8:16:50 AM: > We've added the following to your /opt/buildhome/.profile
8:16:50 AM: > If this isn't the profile of your current shell then please add the following to your correct profile:
8:16:50 AM: export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
8:16:50 AM: 
8:16:51 AM: > Successfully installed Yarn 1.3.2! Please open another terminal where the `yarn` command will now be available.
8:16:51 AM: Installing NPM modules using Yarn version 1.3.2
8:16:52 AM: yarn install v1.3.2
8:16:52 AM: [1/5] Validating package.json...
8:16:52 AM: error enery-iot-app@1.0.0: The engine "node" is incompatible with this module. Expected version "10.11.0".
8:16:52 AM: error enery-iot-app@1.0.0: The engine "yarn" is incompatible with this module. Expected version "1.10.1".
8:16:52 AM: error Found incompatible module
8:16:52 AM: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
8:16:52 AM: Error during Yarn install
8:16:52 AM: Error running command: Build script returned non-zero exit code: 1
8:16:52 AM: Failing build: Failed to build site
8:16:52 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
8:16:52 AM: Finished processing build request in 12.384456438s

下面是我的package.json文件

{
  "name": "enery-iot-app",
  "version": "1.0.0",
  "private": true,
  "engines": {
    "npm": "6.4.1",
    "node": "10.11.0",
    "yarn": "1.10.1"
  },
  "dependencies": {
    "antd": "^3.0.3",
    "antd-local-icon": "^0.1.3",
    "apollo-boost": "^0.1.16",
    "axios": "^0.18.0",
    "classnames": "^2.2.5",
    "clone": "^2.1.1",
    "express": "^4.16.3",
    "firebase": "^5.5.1",
    "graphql": "0.13.0",
    "history": "^4.6.3",
    "nprogress": "^0.2.0",
    "plotly.js": "^1.41.2",
    "postcss-inline-rtl": "^0.9.8",
    "react": "^16.2.0",
    "react-apollo": "^2.2.4",
    "react-dom": "^16.2.0",
    "react-intl": "^2.3.0",
    "react-placeholder": "^2.0.0",
    "react-plotly.js": "^2.2.0",
    "react-redux": "^5.0.4",
    "react-router": "^4.1.1",
    "react-router-dom": "^4.1.0",
    "react-router-redux": "^5.0.0-alpha.5",
    "react-scripts": "1.0.17",
    "react-sidebar": "^2.3.2",
    "react-smooth-scrollbar": "^8.0.6",
    "react-throttle": "^0.3.0",
    "react-window-size-listener": "^1.0.10",
    "recharts": "^1.2.0",
    "redux": "^3.6.0",
    "redux-devtools": "^3.3.2",
    "redux-devtools-dock-monitor": "^1.1.1",
    "redux-devtools-log-monitor": "^1.2.0",
    "redux-saga": "^0.16.0",
    "redux-saga-firebase": "^0.14.1",
    "redux-thunk": "^2.2.0",
    "smooth-scrollbar": "^8.2.5",
    "styled-components": "^2.2.1",
    "styled-theme": "^0.3.3"
  },
  "devDependencies": {
    "react-app-rewired": "^1.4.0"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

不确定为什么构建失败,因为我也提到了引擎,并在package.json文件中指定了节点,npm和yarn版本。

即使已安装的节点版本为v8。 请帮我解决这个问题,因为我无法解决。

1 个答案:

答案 0 :(得分:0)

package.json中,您需要npmnodeyarn的引擎版本。

  "engines": {
    "npm": "6.4.1",
    "node": "10.11.0",
    "yarn": "1.10.1"
  },

上面的输出中Netlify上安装的版本:

Installing yarn at version 1.3.2

Now using node v8.12.0 (npm v6.4.1)

确保需要这些版本,然后您可以在项目的存储库根目录中通过environment variables设置adding a netlify.toml file

netlify.toml

[build.environment]
  NODE_VERSION = "10.11.0"
  YARN_VERSION = "1.10.1"
  NPM_VERSION = "6.4.1"