Build is faling when I'm trying to deploy on Heroku

Viewed 155

I'm having trouble getting my application on Heroku, I'm getting the following error, I've already searched around here on Stackoverflow and I've seen responses saying to remove /node_modules and package-lock.json, but unfortunately the error remains.

Output:

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Node.js app detected
       
-----> Creating runtime environment
   
   NPM_CONFIG_LOGLEVEL=error
   NODE_VERBOSE=false
   NODE_ENV=production
   NODE_MODULES_CACHE=true
   
-----> Installing binaries
   engines.node (package.json):  14.16.1
   engines.npm (package.json):   unspecified (use default)
   
   Resolving node version 14.16.1...
   Downloading and installing node 14.16.1...
   Using default npm version: 6.14.12
   
-----> Installing dependencies
   Installing node modules
   
   > nodemon@2.0.15 postinstall /tmp/build_1e107d4a/node_modules/nodemon
   > node bin/postinstall || exit 0
   
   Love nodemon? You can now support the project via the open collective:
    > https://opencollective.com/nodemon/donate
   
   added 208 packages in 3.879s
   
-----> Build
   Running build
   
   > teste@1.0.0 build /tmp/build_1e107d4a
   > concurrently "cd airbnb/ && npm run build"
   
   [0] 
   [0] > airbnb@0.1.0 build /tmp/build_1e107d4a/airbnb
   [0] > react-scripts build
   [0] 
   [0] sh: 1: react-scripts: not found
   [0] npm ERR! code ELIFECYCLE
   npm ERR! syscall spawn
   [0] npm ERR! file sh
   npm ERR! errno ENOENT
   [0] npm ERR! airbnb@0.1.0 build: `react-scripts build`
   [0] npm ERR! spawn ENOENT
   [0] npm ERR! 
   [0] npm ERR! Failed at the airbnb@0.1.0 build script.
   [0] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
   [0] 
   [0] npm ERR! A complete log of this run can be found in:
   [0] npm ERR!     /tmp/npmcache.ZNegh/_logs/2021-11-16T19_01_58_803Z-debug.log
   [0] cd airbnb/ && npm run build exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! teste@1.0.0 build: `concurrently "cd airbnb/ && npm run build"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the teste@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.ZNegh/_logs/2021-11-16T19_01_58_824Z-debug.log

-----> Build failed
   
   We're sorry this build is failing! You can troubleshoot common issues here:
   https://devcenter.heroku.com/articles/troubleshooting-node-deploys
   
   If you're stuck, please submit a ticket so we can help:
   https://help.heroku.com/
   
   Love,
   Heroku
   

! Push rejected, failed to compile Node.js app. ! Push failed

1 Answers

Ok, the problem is with react-script, react-scripts is (by default) a devDependency for CRA apps, but Heroku Node buildpack has environment NODE_ENV=production which causes npm install to skip devDeps.

To install those devDeps too:

npm install --only=dev && npm install && npm run build

additional information.

Please check in your server-side (if you are using it)/add Procfile without any extension in the root directory.

and inside the Procfile add web: node here your main file name, for example, index.js in my case.

Please add your pacacge.js code as well so it helps us to help you better.

Related