React 构建在本地运行,但在 Amplify 上失败
Posted
技术标签:
【中文标题】React 构建在本地运行,但在 Amplify 上失败【英文标题】:React build runs locally but fails on Amplify 【发布时间】:2020-12-24 17:24:17 【问题描述】:任何想法这可能是什么或如何在不重新开始的情况下对其进行调试?在 API、GraphQL 和 CI 上投入了大量时间。
这是一个普通的 create-react-app,在 App.js 中做了一些小改动。使用节点 12.18.3 和 npm 6.14.8 在本地启动和构建。使用 npm@6.9.0 和 node@v10.16.0 进行 Amplify 构建失败。
我正在尝试避免使用自定义 Docker 映像来升级节点和 npm。
已编辑以添加 index.js - 构建日志来自尝试将 .js 附加到 ./App 导入
index.js
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: link omitted
serviceWorker.unregister();
App.js
import React from 'react';
import logo from './images/logo.png';
import './App.css';
function App()
return (
<div className="App">
<header className="App-header">
<img src=logo className="App-logo" />
</header>
<div className="menu">
</div>
<section >
<a href="https://learnredux.com/">Learn React</a>
</section>
<footer>
</footer>
</div>
);
export default App;
src 树
src
│ App.css
│ App.js
│ App.test.js
│ aws-exports.js
│ index.css
│ index.js
│ logo.svg
│ serviceWorker.js
│ setupTests.js
│ temp
│
└───images
logo.png
构建日志
# Starting phase: preBuild
# Executing command: npm ci
2020-09-05T18:33:47.898Z [WARNING]: npm
2020-09-05T18:33:47.898Z [WARNING]: WARN prepare removing existing node_modules/ before installation
2020-09-05T18:33:55.521Z [INFO]: > core-js@2.6.11 postinstall /codebuild/output/src330086095/src/redimdv4/node_modules/babel-runtime/node_modules/core-js
> node -e "tryrequire('./postinstall')catch(e)"
2020-09-05T18:33:55.644Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src330086095/src/redimdv4/node_modules/webpack-dev-server/node_modules/fsevents
> node install.js
2020-09-05T18:33:55.697Z [INFO]:
2020-09-05T18:33:55.698Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2020-09-05T18:33:55.713Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src330086095/src/redimdv4/node_modules/watchpack-chokidar2/node_modules/fsevents
> node install.js
2020-09-05T18:33:55.766Z [INFO]:
2020-09-05T18:33:55.767Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2020-09-05T18:33:55.837Z [INFO]: > core-js@3.6.5 postinstall /codebuild/output/src330086095/src/redimdv4/node_modules/core-js
> node -e "tryrequire('./postinstall')catch(e)"
2020-09-05T18:33:55.958Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src330086095/src/redimdv4/node_modules/jest-haste-map/node_modules/fsevents
> node install.js
2020-09-05T18:33:56.011Z [INFO]:
2020-09-05T18:33:56.012Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2020-09-05T18:33:56.060Z [INFO]: > core-js-pure@3.6.5 postinstall /codebuild/output/src330086095/src/redimdv4/node_modules/core-js-pure
> node -e "tryrequire('./postinstall')catch(e)"
2020-09-05T18:33:56.179Z [INFO]: added 1625 packages in 8.297s
2020-09-05T18:33:56.194Z [INFO]: # Completed phase: preBuild
# Starting phase: build
2020-09-05T18:33:56.194Z [INFO]: # Executing command: npm run build
2020-09-05T18:33:56.362Z [INFO]: > redimdv4@0.1.0 build /codebuild/output/src330086095/src/redimdv4
> react-scripts build
2020-09-05T18:33:57.201Z [INFO]: Creating an optimized production build...
2020-09-05T18:33:58.459Z [INFO]: Failed to compile.
2020-09-05T18:33:58.461Z [INFO]: ./src/index.js
Cannot find file './App.js' in './src'.
2020-09-05T18:33:58.469Z [WARNING]: npm
2020-09-05T18:33:58.470Z [WARNING]: ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR!
2020-09-05T18:33:58.471Z [WARNING]: redimdv4@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the redimdv4@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-05T18:33:58.481Z [WARNING]:
2020-09-05T18:33:58.482Z [WARNING]: npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-09-05T18_33_58_471Z-debug.log
2020-09-05T18:33:58.482Z [HELP]: Outputting the npm debug log
0 info it worked if it ends with ok
1 verbose cli [ '/root/.nvm/versions/node/v10.16.0/bin/node',
1 verbose cli '/root/.nvm/versions/node/v10.16.0/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm@6.9.0
3 info using node@v10.16.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle redimdv4@0.1.0~prebuild: redimdv4@0.1.0
6 info lifecycle redimdv4@0.1.0~build: redimdv4@0.1.0
7 verbose lifecycle redimdv4@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle redimdv4@0.1.0~build: PATH: /root/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/codebuild/output/src330086095/src/redimdv4/node_modules/.bin:/usr/local/rvm/gems/ruby-2.4.6/bin:/usr/local/rvm/gems/ruby-2.4.6@global/bin:/usr/local/rvm/rubies/ruby-2.4.6/bin:/usr/local/rvm/bin:/root/.yarn/bin:/root/.config/yarn/global/node_modules/.bin:/root/.nvm/versions/node/v10.16.0/bin:/root/.local/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle redimdv4@0.1.0~build: CWD: /codebuild/output/src330086095/src/redimdv4
10 silly lifecycle redimdv4@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle redimdv4@0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle redimdv4@0.1.0~build: Failed to exec build script
13 verbose stack Error: redimdv4@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/root/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/root/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid redimdv4@0.1.0
15 verbose cwd /codebuild/output/src330086095/src/redimdv4
16 verbose Linux 4.14.186-110.268.amzn1.x86_64
17 verbose argv "/root/.nvm/versions/node/v10.16.0/bin/node" "/root/.nvm/versions/node/v10.16.0/bin/npm" "run" "build"
18 verbose node v10.16.0
19 verbose npm v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error redimdv4@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the redimdv4@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
2020-09-05T18:33:58.484Z [ERROR]: !!! Build failed
2020-09-05T18:33:58.553Z [ERROR]: !!! Non-Zero Exit Code detected
2020-09-05T18:33:58.553Z [INFO]: # Starting environment caching...
2020-09-05T18:33:58.554Z [INFO]: # Environment caching completed
Terminating logging...
【问题讨论】:
【参考方案1】:解决了我自己的问题。代码提交问题。最初使用 app.js 作为纯 javascript 创建。我将其重命名为 App.js 并提交了更改。
我注意到在文件资源管理器和 vs code 中的文件侧边栏中,文件名显示正确,但编辑器选项卡上的名称是 app.js。我将其重命名为renamed.js,提交后将其重命名为App.js,再次提交后推送。
现在构建工作。
【讨论】:
以上是关于React 构建在本地运行,但在 Amplify 上失败的主要内容,如果未能解决你的问题,请参考以下文章
React 图像在本地加载,但不在 AWS Amplify 上
构建失败 - 在 AWS Amplify 中的“npm build”之后检测到非零退出代码
aws-amplify-react 和 @aws-amplify/ui-react 有啥区别?
使用 Amplify 集成构建 AWS Amplify React 应用程序时总是缺少 aws-exports.js