reactjs netlify部署:在“构建站点”阶段失败:生成脚本返回非零退出代码:2

wwwo4jvm  于 2023-06-29  发布在  React
关注(0)|答案(7)|浏览(101)

我试图通过Github将我的reactjs站点部署到Netlify,但没有成功。
错误消息为
在“构建站点”阶段失败:生成脚本返回非零退出代码:2
以下是完整的Netlify日志。

  1. 11:59:46 AM: Build ready to start
  2. 11:59:48 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
  3. 11:59:48 AM: build-image tag: v3.4.1
  4. 11:59:48 AM: buildbot version: 0a44c930054be748eff0c581d346282fece89cc0
  5. 11:59:48 AM: Building without cache
  6. 11:59:48 AM: Starting to prepare the repo for build
  7. 11:59:48 AM: No cached dependencies found. Cloning fresh repo
  8. 11:59:48 AM: git clone https://github.com/Helloiain/movie-app
  9. 11:59:49 AM: Preparing Git Reference refs/heads/master
  10. 11:59:50 AM: Starting build script
  11. 11:59:50 AM: Installing dependencies
  12. 11:59:50 AM: Python version set to 2.7
  13. 11:59:51 AM: v12.18.0 is already installed.
  14. 11:59:52 AM: Now using node v12.18.0 (npm v6.14.4)
  15. 11:59:52 AM: Started restoring cached build plugins
  16. 11:59:52 AM: Finished restoring cached build plugins
  17. 11:59:52 AM: Attempting ruby version 2.7.1, read from environment
  18. 11:59:53 AM: Using ruby version 2.7.1
  19. 11:59:54 AM: Using PHP version 5.6
  20. 11:59:54 AM: 5.2 is already installed.
  21. 11:59:54 AM: Using Swift version 5.2
  22. 11:59:54 AM: Started restoring cached node modules
  23. 11:59:54 AM: Finished restoring cached node modules
  24. 11:59:54 AM: Started restoring cached yarn cache
  25. 11:59:54 AM: Finished restoring cached yarn cache
  26. 11:59:54 AM: Installing yarn at version 1.22.4
  27. 11:59:54 AM: Installing Yarn!
  28. 11:59:54 AM: > Downloading tarball...
  29. 11:59:54 AM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.aq7yGqZqlV
  30. 11:59:54 AM: % Total % Received % Xferd Average Speed Time Time Time Current
  31. 11:59:54 AM: Dload Upload Total Spent Left Speed
  32. 11:59:54 AM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
  33. 11:59:54 AM: 100 80 100 80 0 0 285 0 --:--:-- --:--:-- --:--:-- 285
  34. 11:59:54 AM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
  35. 11:59:54 AM: 100 93 100 93 0 0 156 0 --:--:-- --:--:-- --:--:-- 556
  36. 11:59:55 AM: 100 643 100 643 0 0 749 0 --:--:-- --:--:-- --:--:-- 749
  37. 11:59:55 AM: 100 1215k 100 1215k 0 0 947k 0 0:00:01 0:00:01 --:--:-- 947k
  38. 11:59:55 AM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.aq7yGqZqlV.asc
  39. 11:59:55 AM: 100 84 100 84 0 0 3088 0 --:--:-- --:--:-- --:--:-- 3088
  40. 11:59:55 AM: 100 97 100 97 0 0 1692 0 --:--:-- --:--:-- --:--:-- 1692
  41. 11:59:55 AM: 100 647 100 647 0 0 7321 0 --:--:-- --:--:-- --:--:-- 7321
  42. 11:59:55 AM: 0 1028 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
  43. 11:59:55 AM: 100 1028 100 1028 0 0 8135 0 --:--:-- --:--:-- --:--:-- 1003k
  44. 11:59:55 AM: > Verifying integrity...
  45. 11:59:55 AM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
  46. 11:59:55 AM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
  47. 11:59:55 AM: gpg: WARNING: This key is not certified with a trusted signature!
  48. 11:59:55 AM: gpg: There is no indication that the signature belongs to the owner.
  49. 11:59:55 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
  50. 11:59:55 AM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
  51. 11:59:55 AM: > GPG signature looks good
  52. 11:59:55 AM: > Extracting to ~/.yarn...
  53. 11:59:55 AM: > Adding to $PATH...
  54. 11:59:56 AM: > Successfully installed Yarn 1.22.4! Please open another terminal where the `yarn` command will now be available.
  55. 11:59:56 AM: Installing NPM modules using Yarn version 1.22.4
  56. 11:59:57 AM: yarn install v1.22.4
  57. 11:59:57 AM: [1/4] Resolving packages...
  58. 11:59:58 AM: [2/4] Fetching packages...
  59. 12:00:22 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
  60. 12:00:22 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
  61. 12:00:22 PM: info fsevents@1.2.12: The platform "linux" is incompatible with this module.
  62. 12:00:22 PM: info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
  63. 12:00:22 PM: [3/4] Linking dependencies...
  64. 12:00:22 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
  65. 12:00:22 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "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".
  66. 12:00:34 PM: [4/4] Building fresh packages...
  67. 12:00:36 PM: success Saved lockfile.
  68. 12:00:36 PM: Done in 38.98s.
  69. 12:00:36 PM: NPM modules installed using Yarn
  70. 12:00:36 PM: Started restoring cached go cache
  71. 12:00:36 PM: Finished restoring cached go cache
  72. 12:00:36 PM: go version go1.14.4 linux/amd64
  73. 12:00:36 PM: go version go1.14.4 linux/amd64
  74. 12:00:36 PM: Installing missing commands
  75. 12:00:36 PM: Verify run directory
  76. 12:00:37 PM:
  77. 12:00:37 PM: ┌─────────────────────────────┐
  78. 12:00:37 PM: Netlify Build
  79. 12:00:37 PM: └─────────────────────────────┘
  80. 12:00:37 PM:
  81. 12:00:37 PM: Version
  82. 12:00:37 PM: @netlify/build 5.0.2
  83. 12:00:37 PM:
  84. 12:00:37 PM: Flags
  85. 12:00:37 PM: deployId: 5f9069020af24e00933f58d3
  86. 12:00:37 PM: mode: buildbot
  87. 12:00:37 PM:
  88. 12:00:37 PM: Current directory
  89. 12:00:37 PM: /opt/build/repo
  90. 12:00:37 PM:
  91. 12:00:37 PM: Config file
  92. 12:00:37 PM: No config file was defined: using default values.
  93. 12:00:37 PM:
  94. 12:00:37 PM: Context
  95. 12:00:37 PM: production
  96. 12:00:37 PM:
  97. 12:00:37 PM: ┌───────────────────────────────────┐
  98. 12:00:37 PM: 1. Build command from Netlify app
  99. 12:00:37 PM: └───────────────────────────────────┘
  100. 12:00:37 PM:
  101. 12:00:37 PM: $ yarn build
  102. 12:00:38 PM: yarn run v1.22.4
  103. 12:00:38 PM: $ react-scripts build
  104. 12:00:39 PM: Creating an optimized production build...
  105. 12:00:41 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
  106. 12:00:42 PM: Failed to compile.
  107. 12:00:42 PM:
  108. 12:00:42 PM: ./src/index.js
  109. 12:00:42 PM: Cannot find file './app.js' in './src'.
  110. 12:00:42 PM: error Command failed with exit code 1.
  111. 12:00:42 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  112. 12:00:42 PM:
  113. 12:00:42 PM: ┌─────────────────────────────┐
  114. 12:00:42 PM: "build.command" failed
  115. 12:00:42 PM: └─────────────────────────────┘
  116. 12:00:42 PM:
  117. 12:00:42 PM: Error message
  118. 12:00:42 PM: Command failed with exit code 1: yarn build
  119. 12:00:42 PM:
  120. 12:00:42 PM: Error location
  121. 12:00:42 PM: In Build command from Netlify app:
  122. 12:00:42 PM: yarn build
  123. 12:00:42 PM:
  124. 12:00:42 PM: Resolved config
  125. 12:00:42 PM: build:
  126. 12:00:42 PM: command: yarn build
  127. 12:00:42 PM: commandOrigin: ui
  128. 12:00:42 PM: publish: /opt/build/repo/build
  129. 12:00:42 PM: Caching artifacts
  130. 12:00:42 PM: Started saving node modules
  131. 12:00:42 PM: Finished saving node modules
  132. 12:00:42 PM: Started saving build plugins
  133. 12:00:42 PM: Finished saving build plugins
  134. 12:00:42 PM: Started saving yarn cache
  135. 12:00:42 PM: Finished saving yarn cache
  136. 12:00:42 PM: Started saving pip cache
  137. 12:00:42 PM: Finished saving pip cache
  138. 12:00:42 PM: Started saving emacs cask dependencies
  139. 12:00:42 PM: Finished saving emacs cask dependencies
  140. 12:00:42 PM: Started saving maven dependencies
  141. 12:00:42 PM: Finished saving maven dependencies
  142. 12:00:42 PM: Started saving boot dependencies
  143. 12:00:42 PM: Finished saving boot dependencies
  144. 12:00:42 PM: Started saving go dependencies
  145. 12:00:42 PM: Finished saving go dependencies
  146. 12:00:45 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
  147. 12:00:45 PM: Failing build: Failed to build site
  148. 12:00:45 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
  149. 12:00:45 PM: Finished processing build request in 57.736891768s

在搜索了类似的问题后,我认为这可能是依赖问题,然而,在使用“Yarn”安装依赖后,我仍然遇到了同样的问题。在本地使用“yarn build”进行构建也很好。

deyfvvtc

deyfvvtc1#

我在尝试将我的单页React JSWeb应用程序部署到Netlify时发现了相同的错误。
以下是我解决此问题并成功部署站点所遵循的过程。
1.进入【站点设置】。

1.在菜单中选择【构建部署】下拉菜单。
1.在下拉菜单中选择【持续部署】选项卡。

  • 在【构建设置】下,选择【编辑设置】。
  • 修改***build命令***为CI= npm run build
  • 单击【保存】。

  • 然后从下拉菜单中选择【环境】选项卡。
  • 选择【编辑变量】。
    输入CI,***值输入false
  • 单击【保存】。

  • 最后,再次尝试部署站点。

这将帮助您解决与在Netlify中托管“Rect JS”应用程序相关的问题,您的应用程序将成功部署。

展开查看全部
pod7payv

pod7payv2#

您必须更改环境变量的值,以便成功构建它。请按照以下步骤操作:

  • 转到Deploy settings
  • 单击Environment,然后单击Edit Variables按钮。
  • 设置Key为CI,Value为false
  • 现在点击Save按钮。

现在,您可以构建和部署项目而不会出现错误。

fnatzsnv

fnatzsnv3#

按照这些确切的步骤,因为我有同样的问题,直到我这样做,如所述:
1.进入站点设置>构建部署>持续部署。
1.进入【构建设置】>【编辑设置】。
1.将Build Command编辑为CI= npm run build(请看npm run build=之间的空格。拥有它是非常重要的)。
1.在发布目录中写入build
1.进入环境>编辑变量。
1.必须在Key中写入变量CI,在Value中写入false
1.点击【保存】。
1.进入【部署】,在第二部分,点击【触发部署】,选择【清空缓存】和【部署站点】。
这将解决bug,现在您可以部署您的站点。好好享受吧!

ykejflvf

ykejflvf4#

想明白了它是app.js的 shell ,我只需要把它改成App.js,

7d7tgy0s

7d7tgy0s5#

我得到这个错误是因为我有一个编译错误,但我不知道,因为未暂存的本地更改将它隐藏在我的本地环境中。
在我的例子中,newFile.js还没有提交。但是newFile.js被导入到committedFile.js中。由于newFile.js未提交,构建编译失败,没有文件可导入到committedFile.js

查看是否有隐藏的编译错误:

使用git stash -u存储本地未提交的更改,并查看是否在本地获得编译错误。

kupeojn6

kupeojn66#

我也遇到了同样的错误,但我的错误使用此命令CI= npm run build清除,但随后我再次遇到相同的错误,然后尝试此操作,但这一次它不起作用,但我通过以下方法解决了问题:

  • 如果部署失败,请尝试恢复推送,然后使用CI= npm run build重试
  • 大多数错误是由于新版本或您安装的不受支持的软件包(与netlify优化不匹配)
  • 在终端中总是会显示一条错误消息,请尝试识别导致错误的软件包-尝试删除或查询netlify支持的版本
oyxsuwqo

oyxsuwqo7#

我遇到这个问题是因为一些警告和Netlify建议如何修复它们,在构建成功之后,所以可能只需查看日志并找到答案。

相关问题