Deploying MERN to Heroku is failing - node.js

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.

Related

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

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.

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

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 Node and Angular to Heroku error

I'm trying to learn how to deploy a Node and Angular app to Heroku and am getting an error.
Here are the steps I'm taking
Create an empty repo on GitHub.
Deploy the pre-create project, which creates a new heroku app.
Next, I download and copy the code that is in the pre-created project.
Then I push that code up to the empty repo I created step 1.
I then go back to Heroku and manually deploy connecting my repo to it.
When deploying I get an error that I don't know how to resolve. This is strange to me since I have the pre-configured Heroku app along with the exact same code.
> Building dependencies
Installing node modules (package.json)
> mean-contactlist-angular2#0.0.0 postinstall /tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e
> ng build
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
at Class.run (/tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/node_modules/#angular/cli/tasks/build.js:16:56)
at Class.run (/tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/node_modules/#angular/cli/commands/build.js:143:26)
at Class.<anonymous> (/tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/node_modules/#angular/cli/ember-cli/lib/models/command.js:134:17)
at process._tickCallback (internal/process/next_tick.js:109:7)
npm ERR! Linux 3.13.0-133-generic
npm ERR! argv "/tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/.heroku/node/bin/node" "/tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/.heroku/node/bin/npm" "install" "--unsafe-perm" "--userconfig" "/tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/.npmrc"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! mean-contactlist-angular2#0.0.0 postinstall: `ng build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mean-contactlist-angular2#0.0.0 postinstall script 'ng build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mean-contactlist-angular2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ng build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs mean-contactlist-angular2
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mean-contactlist-angular2
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /tmp/build_00959509bf83606e9586c85b4acd5130/worldofnick-LocalBeats-34154d74169daf6c8cdab1e9e5407bd4e4f9c24e/npm-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 ran into this problem while deploying to Heroku today. In your package.json, make sure you are correctly specifying node as your engine. Example:
"engines": {
"node": "^8.0.0"
},

Resources