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

时间:2020-09-05 20:12:29

标签: reactjs npm aws-amplify npm-scripts

有什么主意吗?如何调试而不重新开始?在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" alt="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 "try{require('./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 "try{require('./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 "try{require('./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 个答案:

答案 0 :(得分:1)

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

我注意到在文件浏览器和vs代码中的文件侧栏中,文件名正确显示,但在编辑器选项卡上的名称为app.js。我将其重命名为named.js,将其提交,然后将其重命名为App.js,然后再次提交,然后再推送。

该版本现在可以使用。