AV8R
AV8R

Reputation: 303

React build runs locally but fails on Amplify

Any ideas what this could be or how to debug it without starting over? Lots of time invested in API, GraphQL and CI.

This is a vanilla create-react-app with some minor changes in the App.js. Starts and builds locally with node 12.18.3 and npm 6.14.8. Fails in Amplify build using [email protected] and [email protected].

I'm trying to avoid custom Docker image to upgrade node and npm.

edited to add index.js - build log is from an attempt to append .js to the ./App import

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 Tree

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

Build log

                                 # 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]: > [email protected] 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]: > [email protected] 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]: > [email protected] 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]: > [email protected] postinstall /codebuild/output/src330086095/src/redimdv4/node_modules/core-js
                                 > node -e "try{require('./postinstall')}catch(e){}"
2020-09-05T18:33:55.958Z [INFO]: > [email protected] 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]: > [email protected] 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]: > [email protected] 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]: [email protected] build: `react-scripts build`
                                    npm ERR! Exit status 1
                                    npm ERR!
                                    npm ERR! Failed at the [email protected] 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 [email protected]
                                 3 info using [email protected]
                                 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
                                 5 info lifecycle [email protected]~prebuild: [email protected]
                                 6 info lifecycle [email protected]~build: [email protected]
                                 7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
                                 8 verbose lifecycle [email protected]~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 [email protected]~build: CWD: /codebuild/output/src330086095/src/redimdv4
                                 10 silly lifecycle [email protected]~build: Args: [ '-c', 'react-scripts build' ]
                                 11 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
                                 12 info lifecycle [email protected]~build: Failed to exec build script
                                 13 verbose stack Error: [email protected] 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 [email protected]
                                 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 [email protected] build: `react-scripts build`
                                 22 error Exit status 1
                                 23 error Failed at the [email protected] 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...

Upvotes: 5

Views: 3741

Answers (1)

AV8R
AV8R

Reputation: 303

Fixed my own problem. Codecommit problem. Originally created as pure javascript with app.js. I renamed it to App.js and committed the change.

I noticed in the file explorer and the files sidebar in vs code the file name was displayed correctly but the name on the editor tab was app.js. I renamed it to renamed.js, committed it then renamed it to App.js and committed it again then pushed.

The build works now.

Upvotes: 2

Related Questions