在netlify上部署构建时出错(错误:1)

时间:2019-07-14 16:29:38

标签: reactjs web-deployment netlify

我有一个通过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'.

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

Sultan H.的答案部分正确。

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