Failed to deploy expressjs to heroku - node.js

so im trying to deploy my expressjs server , i've already done the login between heroku and github but after i execute the command git push heroku master i get this type of error
-----> 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): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 14.x...
Downloading and installing node 14.17.3...
Using default npm version: 6.14.13
-----> Installing dependencies
Prebuild detected (node_modules already exists)
Rebuilding any native modules
> bcrypt#5.0.1 install /tmp/build_e68eccdb/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
sh: 1: node-pre-gyp: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! bcrypt#5.0.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the bcrypt#5.0.1 install 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.F7UGs/_logs/2021-07-17T18_32_02_636Z-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_modules checked into source control
https://devcenter.heroku.com/articles/node-best-practices#only-git-the-important-bits
- 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
this is package.json
{
"name": "Server",
"version": "1.0.0",
"description": "",
"main": "Server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.12.4",
"nexmo": "^2.9.1",
"nodemailer": "^6.6.0",
"textbelt": "0.0.4",
"twilio": "^3.61.0"
}
}
i tried deleting node_modules and package-lock.json and reinstall them again but it doesnt work
is there any solution for this ?
Thanks !

Related

Heroku Shopify Application Error 'npm ERR! ERESOLVE unable to resolve dependency tree'

Greetings I have a problem with Heroku because it's don't want to install legacy packages for my Shopify app, my Shopify app is on Github and I just set up everything that my application needs, but when I deploy the main branch on Heroku I get this error in Heroku console below, can someone help me fix this?
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
USE_NPM_INSTALL=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=false
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 16.x...
Downloading and installing node 16.14.0...
Using default npm version: 8.3.1
-----> Restoring cache
Caching has been disabled because NODE_MODULES_CACHE=false
-----> Installing dependencies
Installing node modules (package.json + package-lock)
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: shopify-app-node#1.0.0
npm ERR! Found: react#16.14.0
npm ERR! node_modules/react
npm ERR! react#"^16.10.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^17.0.2 || ^18.0.0-0" from next#12.0.10
npm ERR! node_modules/next
npm ERR! next#"^12.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /tmp/npmcache.CTfHl/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.CTfHl/_logs/2022-02-10T12_18_50_156Z-debug-0.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
My package.json
{
"name": "shopify-app-node",
"version": "1.0.0",
"description": "Shopify's node app for CLI tool",
"scripts": {
"test": "jest",
"dev": "cross-env NODE_ENV=development nodemon ./server/index.js --watch ./server/index.js",
"build": "NEXT_TELEMETRY_DISABLED=1 next build",
"start": "cross-env NODE_ENV=production node ./server/index.js"
},
"engines": {
"node": "16.14.0",
"npm": "8.4.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Shopify/shopify-app-node.git"
},
"author": "Shopify Inc.",
"license": "MIT",
"bugs": {
"url": "https://github.com/shopify/shopify-app-node/issues"
},
"dependencies": {
"#babel/core": "7.12.10",
"#babel/polyfill": "^7.6.0",
"#babel/preset-env": "^7.12.11",
"#babel/register": "^7.12.10",
"#shopify/app-bridge-react": "^2.0.2",
"#shopify/app-bridge-utils": "^2.0.2",
"#shopify/koa-shopify-auth": "^4.1.2",
"#shopify/polaris": "^6.2.0",
"apollo-boost": "^0.4.9",
"axios": "^0.25.0",
"cross-env": "^7.0.3",
"dotenv": "^8.2.0",
"graphql": "^14.5.8",
"isomorphic-fetch": "^3.0.0",
"koa": "^2.13.1",
"koa-bodyparser": "^4.3.0",
"koa-compress": "^5.1.0",
"koa-cors": "0.0.16",
"koa-logger": "^3.2.1",
"koa-router": "^10.0.0",
"koa-session": "^6.1.0",
"mysql2": "^2.3.3",
"next": "^12.0.2",
"next-env": "^1.1.0",
"node-fetch": "^2.6.7",
"react": "^16.10.1",
"react-apollo": "^3.1.3",
"react-dom": "^16.10.1",
"sequelize": "^6.13.0",
"slugify": "^1.6.5",
"validator": "^13.7.0",
"webpack": "^4.44.1"
},
"devDependencies": {
"#babel/plugin-transform-runtime": "^7.12.10",
"#babel/preset-stage-3": "^7.0.0",
"babel-jest": "26.6.3",
"babel-register": "^6.26.0",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.6",
"husky": "^4.3.6",
"jest": "26.6.3",
"lint-staged": "^10.5.4",
"nodemon": "^2.0.7",
"prettier": "2.2.1",
"react-addons-test-utils": "15.6.2",
"react-test-renderer": "16.14.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,css,json,md}": [
"prettier --write"
]
}
}
If you cannot reproduce locally, set package.json engines: to match your local development
This is not the OP's exact issue as they had specified engines: and reproduced locally, so definitely what they needed was to resolve it locally first, which is a subset of the infinite Unable to resolve dependency tree error when installing npm packages
But I couldn't reproduce locally even after delting node_modules and package-lock.json, so as soon as I set engines:, which Heroku respects, to match my local working setup node --version and npm --version with:
"engines": {
"node": "14.17.0",
"npm": "6.14.13"
},
it started working on Heroku. Here's my failing package.json to which the engines were added. The error was:
remote: Installing node modules (package.json)
remote: npm ERR! code ERESOLVE
remote: npm ERR! ERESOLVE unable to resolve dependency tree
remote: npm ERR!
remote: npm ERR! While resolving: conduit-node#1.0.0
remote: npm ERR! Found: react#17.0.2
remote: npm ERR! node_modules/react
remote: npm ERR! react#"17.0.2" from the root project
remote: npm ERR!
remote: npm ERR! Could not resolve dependency:
remote: npm ERR! peer react#"^16.11.0" from swr#0.3.0
remote: npm ERR! node_modules/swr
remote: npm ERR! swr#"0.3.0" from the root project
Prior to the fix, Heroku logs show it was using:
remote: Downloading and installing node 16.14.0...
remote: Using default npm version: 8.3.1
For this reason, you should Always, Always, set engines to match your local setup on a Heroku project.
Ciro Santilli's way solved my problem:
I added these lines to package.json and the problem fixed:
"engines": {
"node": "16.x",
"npm": "8.5.5"
},
Apparently for me the "knex" module that I use is not compatible with newer npm (I am not sure).
You may use .npmrc
New versions of npm do not allow you to install dependencies with different versions of peer dependencies because it may lead to breaking change. So if you are sure that everything works without any issues, maybe you have good tests. Just add --legacy-peer-deps or --force after your npm script (basically it's npm i). But it's so annoying to write it, instead you can create '.npmrc' file in the root of your project with following:
legacy-peer-deps=true
...
or even:
force=true
...
Now you don't need to add --legacy-peer-deps or --force manually.
ps. It also solves the problem with Heroku when you cannot explicitly use npm i --legacy-peer-deps. At least I don't know how to do so.
I found a solution. You can add config variables in Heroku apps.
Go to the app in Heroku -> settings -> Reveal Config Vars
Add a new config var with the key: NPM_CONFIG_LEGACY_PEER_DEPS and value true, and then redeploy.
I install these old packages with npm install --force
I run npm outdated
I see what packages are in red
I do upgrade from the current version to the wanted version with npm install --save packagename#wanted_version
Remove any empty files that you may have in your project
Uploaded to git
Deploy to Heroku
Your lock file contains conflicting dependencies. Since you were able to reproduce the error locally using npm ci we have a good way to test a fix locally.
It looks like you are depending directly on React 16. Is that something that you need directly, or is it just a dependency for Next.js?
If it's not something you need directly, upgrade it per the Next.js docs:
npm install react#latest react-dom#latest
That should modify your package-lock.json. Then try installing from the lock file again with npm ci. If that fixes things, commit the change and redeploy.
On the other hand, if you are directly depending on React 16 and cannot upgrade you'll have to consider rolling back to an earlier version of Next.js.

Unable to git push my node.js server to Heroku, says no bower.json present

I am developing a Node.js server for my MERN application and trying to deploy the server on Heroku. However, after I followed the usual commands on Heroku's page for my app, and run git add ., git commit -am "Deploy commit", and git push heroku master, it wasn't able to successfully push the commit.
I have attached my package.json and log file below.
My package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "bower install && grunt build",
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"bower": "^1.8.13",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.2",
"mongoose": "^6.1.2",
"multer": "^1.4.4",
"nodemon": "^2.0.15",
"path": "^0.12.7"
},
"engines": {
"node": "16.x",
"npm": "8.x"
}
}
My logfile:
-----> 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): 16.x
engines.npm (package.json): 8.x
Resolving node version 16.x...
Downloading and installing node 16.13.1...
Bootstrapping npm 8.x (replacing 8.1.2)...
npm 8.x installed
-----> Installing dependencies
Installing node modules
> server#1.0.0 postinstall
> node ./node_modules/bower/bin/bower install
bower ENOENT No bower.json present
npm ERR! code 1
npm ERR! path /tmp/build_c71e20e4
npm ERR! command failed
npm ERR! command sh -c node ./node_modules/bower/bin/bower install
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.nktzc/_logs/2022-01-01T10_48_31_122Z-debug-0.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
After encountering the above error, I added a registry for my .bowerrc file like so:
{
"registry": "https://registry.bower.io"
}
Even this hasn't been really helpful.
How can I fix this?
After a bit of research, I got the build success message. Here's what I did to get it working:
So the first thing I did was npm install bower-json.
After that, I used bower init and initialized the app.
Then I removed the build under scripts in package.json.
Following this, I went for another git add, git commit, and git push heroku master.
This process got my build successful!

ERR_INVALID_ARG_TYPE error with prisma during Heroku deployment

first of all, thank you for your help!
I've been trying to deploy my backend app in node.js but everytime I do I'd run into the same issue and I don't know what is that? it was working fine until yesterday
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_PRODUCTION=true
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_MODULE_CACHE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 14.x...
Downloading and installing node 14.16.0...
Using default npm version: 6.14.11
-----> Installing dependencies
Installing node modules
> #prisma/client#2.16.1 postinstall /tmp/build_9659a05e/node_modules/#prisma/client
> node scripts/postinstall.js
warning In order to use "#prisma/client", please install Prisma CLI. You can install it with "npm add -D prisma".
> avenidaz-node#1.0.0 postinstall /tmp/build_9659a05e
> npx prisma generate
Prisma schema loaded from prisma/schema.prisma
Error:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Object
at validateString (internal/validators.js:124:11)
at Object.join (path.js:1039:7)
at Object.generateClient (/tmp/build_9659a05e/node_modules/#prisma/client/generator-build/index.js:72910:56)
at async LineStream.<anonymous> (/tmp/build_9659a05e/node_modules/#prisma/client/generator-build/index.js:2802:26)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! avenidaz-node#1.0.0 postinstall: `npx prisma generate`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the avenidaz-node#1.0.0 postinstall 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.WWuef/_logs/2021-04-06T03_48_25_103Z-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
this is my package.json
{
"name": "my aoo",
"version": "1.0.0",
"description": "back end of avenida z",
"main": "src/app.js",
"scripts": {
"postinstall": "npx prisma generate",
"start": "node src/server.js",
"test": "mocha tests/**/*.js --exit"
},
"author": "owner",
"license": "ISC",
"dependencies": {
"#prisma/client": "^2.16.1",
"#sendgrid/mail": "^7.4.1",
"aws-sdk": "^2.768.0",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-oauth-server": "^2.0.0",
"heroku-ssl-redirect": "^0.1.1",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.2",
"papaparse": "^5.3.0",
"pg": "^8.3.2",
"pgtools": "^0.3.0",
"sequelize": "^6.3.4",
"uuid": "^8.3.1",
"winston": "^3.3.3"
},
"devDependencies": {
"#prisma/cli": "^2.15.0",
"mocha": "^8.3.0",
"prisma": "^2.16.1"
}
}
I already try taking out the carat on the prisma dependecies and even removing the prisma from the package.json and ran npm i
I've also tried reset the app by running repo:reset and re-deployed
I tried rolling back the previous commit but i still get the ran error
I noticed that when i run the console in heroku console to check the package.json (cat package.json), the package.json is not updated at all when i tried removing the carats or the prisma from the package.json,

Why my mern app cannot be deployed to Heroku?

Im trying to deploy my MERN stack app to Heroku, I have done the necessary configuration on my package.json file, I have tried both Heroku CLI and Github Deploy at Dashboard Heroku but somehow it doesn't deploys... I have heroku postbuild script, which i checked on multiple sites and confirmed
here is my package.json;
{
"name": "devconnector",
"version": "1.0.0",
"description": "Social Network for Developers",
"main": "server.js",
"scripts": {
"start": "node server",
"server": "nodemon server",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"engines": {
"node": "14.11.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"config": "^3.3.2",
"express": "^4.17.1",
"express-validator": "^6.6.1",
"gravatar": "^1.8.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.10.7",
"request": "^2.88.2"
},
"devDependencies": {
"concurrently": "^5.3.0",
"nodemon": "^2.0.4"
}
}
here is the error log;
-----> 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): 14.11.0
engines.npm (package.json): unspecified (use default)
Resolving node version 14.11.0...
Downloading and installing node 14.11.0...
Using default npm version: 6.14.8
-----> Installing dependencies
Installing node modules
> nodemon#2.0.4 postinstall /tmp/build_704248b1_/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 324 packages in 7.74s
-----> Build
Running heroku-postbuild
> devconnector#1.0.0 heroku-postbuild /tmp/build_704248b1_
> NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
up to date in 0.245s
found 0 vulnerabilities
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /tmp/build_704248b1_/client/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_704248b1_/client/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.TlmrF/_logs/2020-10-05T13_06_26_346Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 254
npm ERR! devconnector#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix
client && npm run build --prefix client`
npm ERR! Exit status 254
npm ERR!
npm ERR! Failed at the devconnector#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.TlmrF/_logs/2020-10-05T13_06_26_372Z-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

MERN app fails to run "heroku-postbuild" script while being deployed to Heroku

Everything runs just fine until I try to deploy the app to the Heroku. After logging in, these are the terminal commands I run to deploy the app (and the response):
heroku login
heroku: Press any key to open up the browser to login or q to exit:
Logging in... done
Logged in as #hidden
heroku create
Creating app... done, ⬢ lower-donair-61893
https://lower-donair-61893.herokuapp.com/ | https://git.heroku.com/lower-donair-61893.git
git init
Initialized empty Git repository in #hidden
heroku git:remote -a lower-donair-61893
git add .
warning: adding embedded git repository: client
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached client
hint:
hint: See "git help submodule" for more information.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory
git commit -am "make it better"
[master (root-commit) cdaf621] make it better
13 files changed, 2518 insertions(+)
create mode 100644 .gitignore
create mode 160000 client
create mode 100644 config/default.json
create mode 100644 models/Comment.js
create mode 100644 models/Post.js
create mode 100644 models/User.js
create mode 100644 package-lock.json
create mode 100644 package.json
create mode 100644 routes/api/auth.js
create mode 100644 routes/api/posts.js
create mode 100644 routes/api/users.js
create mode 100644 server.js
The "fun" starts when I run the last command:
git push heroku master
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (15/15), done.
Writing objects: 100% (19/19), 28.99 KiB | 1.61 MiB/s, done.
Total 19 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 12.x...
remote: Downloading and installing node 12.18.2...
remote: Using default npm version: 6.14.5
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > nodemon#2.0.4 postinstall /tmp/build_01ff90de74651f20444f369d014096d8/node_modules/nodemon
remote: > node bin/postinstall || exit 0
remote:
remote: Love nodemon? You can now support the project via the open collective:
remote: > https://opencollective.com/nodemon/donate
remote:
remote: added 267 packages from 151 contributors and audited 268 packages in 9.402s
remote:
remote: 12 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 0 vulnerabilities
remote:
remote:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > heroku-postbuild /tmp/build_01ff90de74651f20444f369d014096d8
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote: up to date in 0.219s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_01ff90de74651f20444f369d014096d8/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_01ff90de74651f20444f369d014096d8/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.0iNHH/_logs/2020-07-01T13_46_53_504Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the 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.0iNHH/_logs/2020-07-01T13_46_53_520Z-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: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to lower-donair-61893.
remote:
To https://git.heroku.com/lower-donair-61893.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/lower-donair-61893.git'
So it's an ENOENT, yet I searched for other MERN apps being deployed to Heroku and found this vid:
https://www.youtube.com/watch?v=71wSzpLyW9k&list=PLillGF-RfqbbiTGgA77tGO426V3hRF9iE&index=8
in which he used the same lines of code as I did. Also my app is a "continue" of his series, so the file structures, scripts etc. are the exact same (that means if you navigate to the video's desc, you can see the link to the github repo, which has a lot less, but the key files such as package.json etc. are cloned).
This is the postbuild script I'm trying to run:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
This is a screenshot of my file structure:
file structure
I've been searching for an answer for past 4 hours and found absolutely nothing. The error messages point out this path, but I can't really find it to review the full log.
/tmp/npmcache.0iNHH/_logs/2020-07-01T13_46_53_504Z-debug.log
Please, if you need to see more, tell me and I'll happily provide whatever you need - for now I'll copy all the code in both package.json files (server and client):
Server one:
{
"name": "#hidden",
"version": "1.0.0",
"description": "#hidden",
"main": "server.js",
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server",
"server": "nodemon server",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"keywords": [
#hidden
],
"author": "#hidden",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"concurrently": "^5.2.0",
"config": "^3.3.1",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.19"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
Client one:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"bootstrap": "^4.5.0",
"moment": "^2.27.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-moment": "^0.9.7",
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
"react-router-redux": "^4.0.8",
"react-scripts": "3.4.1",
"react-transition-group": "^4.4.1",
"reactstrap": "^8.4.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5000"
}
I managed to solve this and successfuly deploy the app by removing all the default gitignore exceptions inside my client folder. I don't know why, but there was "/build" included. My final client gitignore file only includes:
/node_modules
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
Check to have the correct commands in the package.json. For me I had the following setup command wrong.
"heroku-postbuild": "npm install && npm run build"
Try to read all errors because they are usually very clear and indicate exactly which command failed at which line.

Resources