React 构建在本地运行,但在 Amplify 上失败

AV8*_*V8R 5 npm reactjs npm-scripts aws-amplify

有什么想法或者如何在不重新开始的情况下调试它吗?在 API、GraphQL 和 CI 上投入了大量时间。

\n

这是一个普通的 create-react-app,在 App.js 中进行了一些细微的更改。使用节点 12.18.3 和 npm 6.14.8 在本地启动和构建。使用 npm@6.9.0 和 node@v10.16.0 进行 Amplify 构建失败。

\n

我试图避免使用自定义 Docker 映像来升级节点和 npm。

\n

编辑以添加 index.js - 构建日志来自尝试将 .js 附加到 ./App 导入

\n

索引.js

\n
import ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport * as serviceWorker from './serviceWorker';\n\nReactDOM.render(\n  <React.StrictMode>  \n    <App />\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: link omitted\nserviceWorker.unregister();\n
Run Code Online (Sandbox Code Playgroud)\n

应用程序.js

\n
import React from 'react';\nimport logo from './images/logo.png';\nimport './App.css';\n\nfunction App() {\n  return (\n    <div className="App">\n      <header className="App-header">\n        <img src={logo} className="App-logo" alt="logo" />  \n      </header>\n\n      <div className="menu">\n\n      </div>\n\n      <section >\n        <a href="https://learnredux.com/">Learn React</a>\n      </section>\n\n      <footer>\n\n      </footer>\n    </div> \n  );\n}\n\nexport default App;\n
Run Code Online (Sandbox Code Playgroud)\n

源树

\n
src      \n\xe2\x94\x82   App.css\n\xe2\x94\x82   App.js\n\xe2\x94\x82   App.test.js\n\xe2\x94\x82   aws-exports.js\n\xe2\x94\x82   index.css\n\xe2\x94\x82   index.js\n\xe2\x94\x82   logo.svg\n\xe2\x94\x82   serviceWorker.js\n\xe2\x94\x82   setupTests.js\n\xe2\x94\x82   temp\n\xe2\x94\x82   \n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80images\n        logo.png\n
Run Code Online (Sandbox Code Playgroud)\n

构建日志

\n
                                 # Starting phase: preBuild\n                                 # Executing command: npm ci\n2020-09-05T18:33:47.898Z [WARNING]: npm\n2020-09-05T18:33:47.898Z [WARNING]: WARN prepare removing existing node_modules/ before installation\n2020-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\n                                 > node -e "try{require('./postinstall')}catch(e){}"\n2020-09-05T18:33:55.644Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src330086095/src/redimdv4/node_modules/webpack-dev-server/node_modules/fsevents\n                                 > node install.js\n2020-09-05T18:33:55.697Z [INFO]: \n2020-09-05T18:33:55.698Z [INFO]: Skipping 'fsevents' build as platform linux is not supported\n2020-09-05T18:33:55.713Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src330086095/src/redimdv4/node_modules/watchpack-chokidar2/node_modules/fsevents\n                                 > node install.js\n2020-09-05T18:33:55.766Z [INFO]: \n2020-09-05T18:33:55.767Z [INFO]: Skipping 'fsevents' build as platform linux is not supported\n2020-09-05T18:33:55.837Z [INFO]: > core-js@3.6.5 postinstall /codebuild/output/src330086095/src/redimdv4/node_modules/core-js\n                                 > node -e "try{require('./postinstall')}catch(e){}"\n2020-09-05T18:33:55.958Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src330086095/src/redimdv4/node_modules/jest-haste-map/node_modules/fsevents\n                                 > node install.js\n2020-09-05T18:33:56.011Z [INFO]: \n2020-09-05T18:33:56.012Z [INFO]: Skipping 'fsevents' build as platform linux is not supported\n2020-09-05T18:33:56.060Z [INFO]: > core-js-pure@3.6.5 postinstall /codebuild/output/src330086095/src/redimdv4/node_modules/core-js-pure\n                                 > node -e "try{require('./postinstall')}catch(e){}"\n2020-09-05T18:33:56.179Z [INFO]: added 1625 packages in 8.297s\n2020-09-05T18:33:56.194Z [INFO]: # Completed phase: preBuild\n                                 # Starting phase: build\n2020-09-05T18:33:56.194Z [INFO]: # Executing command: npm run build\n2020-09-05T18:33:56.362Z [INFO]: > redimdv4@0.1.0 build /codebuild/output/src330086095/src/redimdv4\n                                 > react-scripts build\n2020-09-05T18:33:57.201Z [INFO]: Creating an optimized production build...\n2020-09-05T18:33:58.459Z [INFO]: Failed to compile.\n2020-09-05T18:33:58.461Z [INFO]: ./src/index.js\n                                 Cannot find file './App.js' in './src'.\n2020-09-05T18:33:58.469Z [WARNING]: npm\n2020-09-05T18:33:58.470Z [WARNING]: ERR! code ELIFECYCLE\n                                    npm ERR! errno 1\n                                    npm ERR!\n2020-09-05T18:33:58.471Z [WARNING]: redimdv4@0.1.0 build: `react-scripts build`\n                                    npm ERR! Exit status 1\n                                    npm ERR!\n                                    npm ERR! Failed at the redimdv4@0.1.0 build script.\n                                    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n2020-09-05T18:33:58.481Z [WARNING]: \n2020-09-05T18:33:58.482Z [WARNING]: npm ERR! A complete log of this run can be found in:\n                                    npm ERR!     /root/.npm/_logs/2020-09-05T18_33_58_471Z-debug.log\n2020-09-05T18:33:58.482Z [HELP]: Outputting the npm debug log\n                                 0 info it worked if it ends with ok\n                                 1 verbose cli [ '/root/.nvm/versions/node/v10.16.0/bin/node',\n                                 1 verbose cli   '/root/.nvm/versions/node/v10.16.0/bin/npm',\n                                 1 verbose cli   'run',\n                                 1 verbose cli   'build' ]\n                                 2 info using npm@6.9.0\n                                 3 info using node@v10.16.0\n                                 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]\n                                 5 info lifecycle redimdv4@0.1.0~prebuild: redimdv4@0.1.0\n                                 6 info lifecycle redimdv4@0.1.0~build: redimdv4@0.1.0\n                                 7 verbose lifecycle redimdv4@0.1.0~build: unsafe-perm in lifecycle true\n                                 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\n                                 9 verbose lifecycle redimdv4@0.1.0~build: CWD: /codebuild/output/src330086095/src/redimdv4\n                                 10 silly lifecycle redimdv4@0.1.0~build: Args: [ '-c', 'react-scripts build' ]\n                                 11 silly lifecycle redimdv4@0.1.0~build: Returned: code: 1  signal: null\n                                 12 info lifecycle redimdv4@0.1.0~build: Failed to exec build script\n                                 13 verbose stack Error: redimdv4@0.1.0 build: `react-scripts build`\n                                 13 verbose stack Exit status 1\n                                 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)\n                                 13 verbose stack     at EventEmitter.emit (events.js:198:13)\n                                 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)\n                                 13 verbose stack     at ChildProcess.emit (events.js:198:13)\n                                 13 verbose stack     at maybeClose (internal/child_process.js:982:16)\n                                 13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)\n                                 14 verbose pkgid redimdv4@0.1.0\n                                 15 verbose cwd /codebuild/output/src330086095/src/redimdv4\n                                 16 verbose Linux 4.14.186-110.268.amzn1.x86_64\n                                 17 verbose argv "/root/.nvm/versions/node/v10.16.0/bin/node" "/root/.nvm/versions/node/v10.16.0/bin/npm" "run" "build"\n                                 18 verbose node v10.16.0\n                                 19 verbose npm  v6.9.0\n                                 20 error code ELIFECYCLE\n                                 21 error errno 1\n                                 22 error redimdv4@0.1.0 build: `react-scripts build`\n                                 22 error Exit status 1\n                                 23 error Failed at the redimdv4@0.1.0 build script.\n                                 23 error This is probably not a problem with npm. There is likely additional logging output above.\n                                 24 verbose exit [ 1, true ]\n2020-09-05T18:33:58.484Z [ERROR]: !!! Build failed\n2020-09-05T18:33:58.553Z [ERROR]: !!! Non-Zero Exit Code detected\n2020-09-05T18:33:58.553Z [INFO]: # Starting environment caching...\n2020-09-05T18:33:58.554Z [INFO]: # Environment caching completed\nTerminating logging...\n
Run Code Online (Sandbox Code Playgroud)\n

AV8*_*V8R 2

解决了我自己的问题。代码提交问题。最初是使用 app.js 作为纯 javascript 创建的。我将其重命名为 App.js 并提交了更改。

我注意到在文件资源管理器和 VS Code 中的文件侧边栏中,文件名显示正确,但编辑器选项卡上的名称是 app.js。我将其重命名为renamed.js,提交,然后将其重命名为App.js,再次提交然后推送。

构建现在可以工作了。