【问题标题】:Error deploying build on netlify (err: 1)在 netlify 上部署构建时出错(错误:1)
【发布时间】:2019-07-15 04:39:08
【问题描述】:

我通过 GitHub 在 Netlify 上部署了一个网站,在提交了一些更改后,Netlify 无法部署当前版本。 运行“npm run build”或在本地运行代码时,我没有收到任何错误。 该网站是使用 create-react-app 构建的。 与之前的提交相比,主要的变化是将资产(图像)添加到整个项目中。 我仔细检查了每个导入,一切都很好。

...
5:15:52 PM: Installing NPM modules using NPM version 6.9.0
5:16:05 PM: npm
5:16:05 PM:  WARN @typescript-eslint/eslint-plugin@1.6.0 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
5:16:05 PM: npm
5:16:05 PM:  WARN @typescript-eslint/parser@1.6.0 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
5:16:05 PM: npm
5:16:05 PM:  WARN @typescript-eslint/typescript-estree@1.6.0 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
5:16:05 PM: npm WARN
5:16:05 PM:  ts-pnp@1.1.2 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
5:16:05 PM: npm
5:16:05 PM:  WARN tsutils@3.14.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 but none is installed. You must install peer dependencies yourself.
5:16:05 PM: npm
5:16:05 PM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/jest-haste-map/node_modules/fsevents):
5:16:05 PM: npm WARN
5:16:05 PM:  notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:16:05 PM: npm
5:16:05 PM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/chokidar/node_modules/fsevents):
5:16:05 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:16:05 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.6 (node_modules/fsevents):
5:16:05 PM: npm
5:16:05 PM:  WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.6: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:16:05 PM: audited 902137 packages in 12.338s
5:16:05 PM: found 0 vulnerabilities
5:16:05 PM: NPM modules installed
5:16:06 PM: Started restoring cached go cache
5:16:06 PM: Finished restoring cached go cache
5:16:06 PM: unset GOOS;
5:16:06 PM: unset GOARCH;
5:16:06 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
5:16:06 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
5:16:06 PM: go version >&2;
5:16:06 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
5:16:06 PM: go version go1.12 linux/amd64
5:16:06 PM: Installing missing commands
5:16:06 PM: Verify run directory
5:16:06 PM: Executing user command: npm run build
5:16:07 PM: > geek-hard-level@0.1.0 build /opt/build/repo
5:16:07 PM: > react-scripts build
5:16:09 PM: Creating an optimized production build...
5:16:14 PM: Failed to compile.
5:16:14 PM: ./src/components/footer/footer.js
5:16:14 PM: Cannot find file '../../assets/images/Logo.jpg' in './src/components/footer'.
5:16:14 PM: npm
5:16:14 PM:  ERR! code ELIFECYCLE
5:16:14 PM: npm
5:16:14 PM: ERR! errno 1
5:16:14 PM: npm
5:16:14 PM: ERR! geek-hard-level@0.1.0 build: `react-scripts build`
5:16:14 PM: npm
5:16:14 PM: ERR!
5:16:14 PM:  Exit status 1
5:16:14 PM: npm
5:16:14 PM:  ERR!
5:16:14 PM: npm ERR!
5:16:14 PM:  Failed at the geek-hard-level@0.1.0 build script.
5:16:14 PM: npm
5:16:14 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
5:16:14 PM: ERR! This is probably not a problem with npm. There is likely additional logging output above.
5:16:14 PM: npm
5:16:14 PM:  ERR! A complete log of this run can be found in:
5:16:14 PM: npm ERR!     /opt/buildhome/.npm/_logs/2019-07-14T16_16_14_542Z-debug.log
5:16:14 PM: Skipping functions preparation step: no functions directory set
5:16:14 PM: Caching artifacts
5:16:14 PM: Started saving node modules
5:16:14 PM: Finished saving node modules
5:16:14 PM: Started saving pip cache
5:16:14 PM: Finished saving pip cache
5:16:14 PM: Started saving emacs cask dependencies
5:16:14 PM: Finished saving emacs cask dependencies
5:16:14 PM: Started saving maven dependencies
5:16:14 PM: Finished saving maven dependencies
5:16:14 PM: Started saving boot dependencies
5:16:14 PM: Finished saving boot dependencies
5:16:14 PM: Started saving go dependencies
5:16:14 PM: Finished saving go dependencies
5:16:14 PM: Error running command: Build script returned non-zero exit code: 1
5:16:14 PM: Failing build: Failed to build site
5:16:14 PM: Finished processing build request in 36.62159852s

我希望构建会像往常一样部署,但出现错误

5:16:14 PM: Cannot find file '../../assets/images/Logo.jpg' in './src/components/footer'.```
I did check this line and it works just fine.

Edit:
Trying to re-deploy the code it throws me the same error but this time instead of being in /components/footer is in /components/contacts, where there is the same Logo.jpg file
```5:31:09 PM: ./src/components/contacts/contacts.js
5:31:09 PM: Cannot find file '../../assets/images/Logo.jpg' in './src/components/contacts'.

【问题讨论】:

  • 只是为了仔细检查,您是否也导出了图像?

标签: reactjs web-deployment netlify


【解决方案1】:

将您的图像资产移动到 React 默认附带的公共文件夹中,并优化您正在使用的路径,例如:

import image from '../../public/images/Logo.jpg'

【讨论】:

    【解决方案2】:

    Sultan H. 回答部分正确。

    我通过将图像文件夹移动到组件的同一文件夹中解决了我的问题。尽管我认为 Netlify 成功发布它并不是一个好的做法。 如果我必须将图像文件夹移动到公共文件夹中,则会引发一个新错误。 快速浏览一下这个新错误,它应该与 create-react-app 相关,它不允许从 src 之外的任何文件夹导入任何内容。

    【讨论】:

      猜你喜欢
      • 2020-10-21
      • 1970-01-01
      • 2021-11-26
      • 2022-01-05
      • 1970-01-01
      • 2021-01-10
      • 2020-05-25
      • 1970-01-01
      • 2022-11-11
      相关资源
      最近更新 更多