Build is faling when I'm trying to deploy on Heroku - node.js

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

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

Problems when deploying MERN stack app in Heroku

What is the solution to this problem? I'm getting this error while trying to deploy a MERN stack in Heroku. What I did is: I configured MONGO_URI, PORT, etc. Pushed all working code in Github still getting this error. What should I do to be able to deploy this app successfully? I tried deploying the application by reading Heroku documentation and watching youtube tutorial.
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> 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): 6.14.12
Resolving node version 14.16.1...
Downloading and installing node 14.16.1...
npm 6.14.12 already installed with node
-----> Installing dependencies
Installing node modules
> nodemon#2.0.7 postinstall /tmp/build_5044977d/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
> bcrypt#5.0.1 install /tmp/build_5044977d/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
[bcrypt] Success: "/tmp/build_5044977d/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
added 365 packages in 9.194s
-----> Build
Running heroku-postbuild
> car-app#1.0.0 heroku-postbuild /tmp/build_5044977d
> NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend
up to date in 0.234s
found 0 vulnerabilities
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /tmp/build_5044977d/frontend/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_5044977d/frontend/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.GU88T/_logs/2021-07-02T10_17_10_423Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 254
npm ERR! car-app#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend`
npm ERR! Exit status 254
npm ERR!
npm ERR! Failed at the car-app#1.0.0 heroku-postbuild 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.GU88T/_logs/2021-07-02T10_17_10_446Z-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
if it is heroku postbuild issue then first run
npm run build
in your local system inside client folder(frontend application), it will throw an error if some dependency is missing inside your react app,
if build command is successful only then delete node_modules and package-lock.json file and then run
npm install

Problems for deploy in heroku node.js app

I cant deploy in heroku my app something wrong with node.js , i tried to delete app , did again the app, npm install, install build packs, all what i saw for internet i did but i cant resolve the problem. The error is:
-----> 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.x
engines.npm (package.json): unspecified (use default)
Resolving node version 14.x...
Downloading and installing node 14.16.1...
Using default npm version: 6.14.12
-----> Installing dependencies
Installing node modules
> react-redux-router#1.0.0 preinstall /tmp/build_94f5a392
> npm set audit false
> fsevents#1.2.13 install /tmp/build_94f5a392/node_modules/fsevents
> node install.js
Skipping 'fsevents' build as platform linux is not supported
> node-sass#4.14.1 install /tmp/build_94f5a392/node_modules/node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-x64-83_binding.node
Download complete
Binary saved to /tmp/build_94f5a392/node_modules/node-sass/vendor/linux-x64-83/binding.node
Caching binary to /tmp/npmcache.fQ3DD/_cacache/node-sass/4.14.1/linux-x64-83_binding.node
> node-sass#4.14.1 postinstall /tmp/build_94f5a392/node_modules/node-sass
> node scripts/build.js
Binary found at /tmp/build_94f5a392/node_modules/node-sass/vendor/linux-x64-83/binding.node
Testing binary
Binary is fine
> core-js#2.6.12 postinstall /tmp/build_94f5a392/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
added 1362 packages in 18.728s
-----> Build
Detected both "build" and "heroku-postbuild" scripts
Running heroku-postbuild
> react-redux-router#1.0.0 heroku-postbuild /tmp/build_94f5a392
> npm run build
> react-redux-router#1.0.0 build /tmp/build_94f5a392
> cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --color
clean-webpack-plugin: /tmp/build_94f5a392/dist has been removed.
<s> [webpack.Progress] 70% building 443/443 modules 0 active
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-redux-router#1.0.0 build: `cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --color`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-redux-router#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.fQ3DD/_logs/2021-04-21T16_54_17_773Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-redux-router#1.0.0 heroku-postbuild: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-redux-router#1.0.0 heroku-postbuild 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.fQ3DD/_logs/2021-04-21T16_54_17_803Z-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
i tried all what i saw, my package.json:
{
"name": "react-redux-router",
"version": "1.0.0",
"description": "Basic skeleton codebase for React/Redux/Router applications.",
"engines": {
"node": "14.x"
},
"scripts": {
"preinstall": "npm set audit false",
"start": "webpack-dev-server --config webpack/dev.config.js --watch",
"build": "cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --color",
"heroku-postbuild": "npm run build",
"precommit": "eslint src",
"prod": "NODE_ENV=production node server.js"
},
what can i do?
Need more details?
Thanks for help
I instaled the buildpacks again and now th error changes, now is this:
code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! react-redux-router#1.0.0 build: `cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --color`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the react-redux-router#1.0.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.LI5Fz/_logs/2021-04-21T18_05_53_894Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! react-redux-router#1.0.0 heroku-postbuild: `npm run build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the react-redux-router#1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.LI5Fz/_logs/2021-04-21T18_05_53_921Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 31c1685dcd402b6a2bc433e60e53fd96f074132a
remote: ! We have detected that you have triggered a build from source code with version 31c1685dcd402b6a2bc433e60e53fd96f074132a
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to funnybooks.
remote:
To https://git.heroku.com/funnybooks.git
! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/funnybooks.git'

error deploying in heroku, rejected error

help me plis !!! I cant deploy mi mean stack app to heroku
mi git repository with the code:
https://github.com/blinkking349/meanstack
log of error:
-----> Build
Running heroku-postbuild
> meanapp#1.0.0 heroku-postbuild /tmp/build_9dad4ae1_
> NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
npm ERR! code EINVALIDTAGNAME
npm ERR! Invalid tag name "~4.0.2,": Tags may not have any characters that encodeURIComponent encodes.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.3rpWs/_logs/2020-10-18T02_45_15_324Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! meanapp#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the meanapp#1.0.0 heroku-postbuild 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.3rpWs/_logs/2020-10-18T02_45_15_340Z-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
The error message says:
Invalid tag name "~4.0.2,"
It looks like you have included a comma inside your version string for TypeScript in your client directory:
"typescript": "~4.0.2,"
Get rid of it:
"typescript": "~4.0.2"
Then commit and redeploy.

Declaration errors when depyoing TypeScript to Heroku

I'm trying to deploy my TypeScript API to Heroku. I have a heroku-prebuild script running npm i && npm i -g typescript && npm run build and a build script running tsc.
So I had installed some new packages with their corresponding types decalrations, and got errors from Heroku:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 12.x
engines.npm (package.json): unspecified (use default)
Resolving node version 12.x...
Downloading and installing node 12.18.4...
Using default npm version: 6.14.6
-----> Restoring cache
- node_modules
-----> Prebuild
Running heroku-prebuild
> swooosh-api#1.0.0 heroku-prebuild /tmp/build_fc3ad6d3
> npm i && npm i -g typescript && npm run build
audited 237 packages in 2.088s
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
/tmp/build_fc3ad6d3/.heroku/node/bin/tsc -> /tmp/build_fc3ad6d3/.heroku/node/lib/node_modules/typescript/bin/tsc
/tmp/build_fc3ad6d3/.heroku/node/bin/tsserver -> /tmp/build_fc3ad6d3/.heroku/node/lib/node_modules/typescript/bin/tsserver
+ typescript#4.0.3
added 1 package from 1 contributor in 1.843s
> swooosh-api#1.0.0 build /tmp/build_fc3ad6d3
> tsc
api/utils/config.ts(1,23): error TS7016: Could not find a declaration file for module 'express-rate-limit'. '/tmp/build_fc3ad6d3/node_modules/express-rate-limit/lib/express-rate-limit.js' implicitly has an 'any' type.
Try `npm install #types/express-rate-limit` if it exists or add a new declaration (.d.ts) file containing `declare module 'express-rate-limit';`
api/utils/config.ts(2,22): error TS7016: Could not find a declaration file for module 'express-slow-down'. '/tmp/build_fc3ad6d3/node_modules/express-slow-down/lib/express-slow-down.js' implicitly has an 'any' type.
Try `npm install #types/express-slow-down` if it exists or add a new declaration (.d.ts) file containing `declare module 'express-slow-down';`
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! swooosh-api#1.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the swooosh-api#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.saClh/_logs/2020-10-04T13_30_28_587Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! swooosh-api#1.0.0 heroku-prebuild: `npm i && npm i -g typescript && npm run build`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the swooosh-api#1.0.0 heroku-prebuild 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.saClh/_logs/2020-10-04T13_30_28_605Z-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
I thought the problem was that Heroku caches the node_modules folder. But I turned that off and I had declaration errors for every single packages...
GitHub repo here
How can I fix this?

Deploying MERN to Heroku is failing

I am trying to deploy this site to Heroku but it is giving me an error of deployment
here is my GitHub code: https://github.com/hazem-kamel/Guestbook-MERN
Logs:
Installing dependencies
Installing node modules (package.json + package-lock)
> nodemon#2.0.2 postinstall /tmp/build_d37d1bf6b721c463128a9d76ebc0c69a/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 194 packages from 102 contributors and audited 195 packages in 4.934s
2 packages are looking for funding
run `npm fund` for details
found 2 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
-----> Build
Running build
> Backend#1.0.0 build /tmp/build_d37d1bf6b721c463128a9d76ebc0c69a
> run-p build:**
sh: 1: run-p: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! Backend#1.0.0 build: `run-p build:**`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the Backend#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.AjLZ0/_logs/2020-05-24T20_24_12_312Z-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
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
I tried several codes but it is also failing : I am deploying by using GitHub code and Heroku automatic deploy
Install/add to your npm/yarn respectively: https://www.npmjs.com/package/npm-run-all
Also, preferred way while building a Heroku app is to delete the node_modules folder and only upload the package.json (that contains dependencies to be installed!). Heroku, while deploying your app automatically scans the package.json file and installs all the depenencies.

Resources