首页 > 解决方案 > 部署一次到 Netlify,然后什么都没有。有任何想法吗?

问题描述

我一直在梳理 stackoverflow 和 netlify 论坛以找到解决方案,但到目前为止还没有成功。我试过添加build: "CI= npm run build"package.json文件中:

"scripts": {
    "start": "craco start",
    "build": "CI= npm run build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },

我也将它添加到了 netlify 构建命令中,以查看它是否可以工作。它在第一次上传之前使用命令部署npm run build,但从那以后什么都没有。这也是它的输出。

Netlify 终端输出:

2:08:30 PM: Build ready to start
2:08:33 PM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a
2:08:33 PM: build-image tag: v3.9.0
2:08:33 PM: buildbot version: cf5e043aa2042f885b3ec4c152fb434068ebe66a
2:08:33 PM: Fetching cached dependencies
2:08:33 PM: Starting to download cache of 108.5MB
2:08:33 PM: Finished downloading cache in 631.631199ms
2:08:33 PM: Starting to extract cache
2:08:38 PM: Finished extracting cache in 4.19839743s
2:08:38 PM: Finished fetching cache in 4.852533785s
2:08:38 PM: Starting to prepare the repo for build
2:08:38 PM: Preparing Git Reference refs/heads/main
2:08:40 PM: Parsing package.json dependencies
2:08:40 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'build' versus './build' in the Netlify UI
2:08:40 PM: Starting build script
2:08:41 PM: Installing dependencies
2:08:41 PM: Python version set to 2.7
2:08:41 PM: Started restoring cached node version
2:08:44 PM: Finished restoring cached node version
2:08:44 PM: v12.18.0 is already installed.
2:08:45 PM: Now using node v12.18.0 (npm v6.14.4)
2:08:45 PM: Started restoring cached build plugins
2:08:45 PM: Finished restoring cached build plugins
2:08:45 PM: Attempting ruby version 2.7.2, read from environment
2:08:46 PM: Using ruby version 2.7.2
2:08:47 PM: Using PHP version 5.6
2:08:47 PM: Started restoring cached node modules
2:08:47 PM: Finished restoring cached node modules
2:08:47 PM: Installing NPM modules using NPM version 6.14.4
2:09:27 PM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
2:09:27 PM: > tsparticles@1.33.2 install /opt/build/repo/node_modules/tsparticles
2:09:27 PM: > node ./scripts/install.js
2:09:27 PM: Thank you for installing tsParticles.
2:09:27 PM: Remember to checkout the official website https://particles.js.org to explore some samples.
2:09:27 PM: You can find more samples on CodePen too: https://codepen.io/collection/DPOage
2:09:27 PM: If you need documentation you can find it here: https://particles.js.org
2:09:27 PM: Remember to leave a star on the tsParticles repository if you like the project and want to support it: https://github.com/matteobruni/tsparticles
2:09:27 PM: > core-js@2.6.12 postinstall /opt/build/repo/node_modules/core-js
2:09:27 PM: > node -e "try{require('./postinstall')}catch(e){}"
2:09:27 PM: > core-js-pure@3.16.1 postinstall /opt/build/repo/node_modules/core-js-pure
2:09:27 PM: > node -e "try{require('./postinstall')}catch(e){}"
2:09:28 PM: > core-js@3.16.1 postinstall /opt/build/repo/node_modules/react-app-polyfill/node_modules/core-js
2:09:28 PM: > node -e "try{require('./postinstall')}catch(e){}"
2:09:30 PM: npm WARN @testing-library/user-event@12.8.3 requires a peer of @testing-library/dom@>=7.21.4 but none is installed. You must install peer dependencies yourself.
2:09:30 PM: npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
2:09:30 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
2:09:30 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2:09:30 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
2:09:30 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2:09:30 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
2:09:30 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2:09:30 PM: added 1141 packages from 205 contributors, removed 368 packages, updated 134 packages and audited 2722 packages in 42.248s
2:09:32 PM: 158 packages are looking for funding
2:09:32 PM:   run `npm fund` for details
2:09:32 PM: found 3 moderate severity vulnerabilities
2:09:32 PM:   run `npm audit fix` to fix them, or `npm audit` for details
2:09:32 PM: NPM modules installed
2:09:32 PM: Started restoring cached go cache
2:09:32 PM: Finished restoring cached go cache
2:09:32 PM: go version go1.14.4 linux/amd64
2:09:32 PM: go version go1.14.4 linux/amd64
2:09:32 PM: Installing missing commands
2:09:32 PM: Verify run directory
2:09:33 PM: ​
2:09:33 PM: ────────────────────────────────────────────────────────────────
2:09:33 PM:   Netlify Build                                                 
2:09:33 PM: ────────────────────────────────────────────────────────────────
2:09:33 PM: ​
2:09:33 PM: ❯ Version
2:09:33 PM:   @netlify/build 18.2.7
2:09:33 PM: ​
2:09:33 PM: ❯ Flags
2:09:33 PM:   baseRelDir: true
2:09:33 PM:   deployId: 6118069e8e7ae10008dd02ff
2:09:33 PM: ​
2:09:33 PM: ❯ Current directory
2:09:33 PM:   /opt/build/repo
2:09:33 PM: ​
2:09:33 PM: ❯ Config file
2:09:33 PM:   No config file was defined: using default values.
2:09:33 PM: ​
2:09:33 PM: ❯ Context
2:09:33 PM:   production
2:09:33 PM: ​
2:09:33 PM: ────────────────────────────────────────────────────────────────
2:09:33 PM:   1. Build command from Netlify app                             
2:09:33 PM: ────────────────────────────────────────────────────────────────
2:09:33 PM: ​
2:09:33 PM: $ CI= npm run build
2:09:33 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:33 PM: > CI= npm run build
2:09:34 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:34 PM: > CI= npm run build
2:09:34 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:34 PM: > CI= npm run build
2:09:34 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:34 PM: > CI= npm run build
2:09:35 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:35 PM: > CI= npm run build
2:09:35 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:35 PM: > CI= npm run build
2:09:35 PM: > bgg_version_3@0.1.0 build /opt/build/repo
2:09:35 PM: > CI= npm run build
2:09:35 PM: > bgg_version_3@0.1.0 build /opt/build/repo

它一直重复,直到我取消部署。任何线索作为我做错了什么?

标签: reactjsdeploymentnetlify

解决方案


问题是以下脚本是一个无限循环:

"scripts": {
    "build": "CI= npm run build"
}

npm run build将运行build脚本,该脚本说 to do npm run build,它会永远递归。

您应该将build规则替换为您实际想要执行的操作,例如:

"scripts": {
    "build": "react-scripts build"
}

推荐阅读