Could not find a required file index.html - Heroku push error - node.js

I am pushing the react-node app to Heroku using Heroku CLI.
build is failing and the error is Could not find a required file index.html
I have checked all the files and everything in place
don't know what am I missing?
I am stuck here for one week.
Please help me
I am pushing the react-node app to Heroku using Heroku CLI.
build is failing and the error is Could not find a required file index.html
I have checked all the files and everything in place
don't know what am I missing?
I am stuck here for one week.
Please help me
Package.json
"main": "server.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"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"
},
Error :
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 398 bytes | 398.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 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): 8.9.4
remote: engines.npm (package.json): 6.2.0
remote:
remote: Resolving node version 8.9.4...
remote: Downloading and installing node 8.9.4...
remote: Bootstrapping npm 6.2.0 (replacing 5.6.0)...
remote: npm 6.2.0 installed
remote:
remote: -----> Restoring cache
remote: - node_modules
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json)
remote: audited 2601 packages in 4.802s
remote: found 0 vulnerabilities
remote:
remote: Running heroku-postbuild
remote:
remote: > devconnector#1.0.0 heroku-postbuild /tmp/build_cb13714e30f186bd579e6f8f21bf9383
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:
remote: > jss#9.8.7 postinstall /tmp/build_cb13714e30f186bd579e6f8f21bf9383/client/node_modules/jss
remote: > node -e "console.log('\u001b[35m\u001b[1mLove JSS? You can now support us on open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/jss/donate\u001b[0m')"
remote:
remote: Love JSS? You can now support us on open collective:
remote: > https://opencollective.com/jss/donate
remote:
remote: > uglifyjs-webpack-plugin#0.4.6 postinstall /tmp/build_cb13714e30f186bd579e6f8f21bf9383/client/node_modules/uglifyjs-webpack-plugin
remote: > node lib/post_install.js
remote:
remote: added 1375 packages from 852 contributors and audited 13755 packages in 46.845s
remote: found 0 vulnerabilities
remote:
remote:
remote: > client#0.1.0 build /tmp/build_cb13714e30f186bd579e6f8f21bf9383/client
remote: > react-scripts build
remote:
**remote: Could not find a required file.
remote: Name: index.html**
remote: Searched in: /tmp/build_cb13714e30f186bd579e6f8f21bf9383/client/public
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! client#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the client#0.1.0 build scr`enter code here`ipt.
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.bspBQ/_logs/2018-10-14T10_57_59_194Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! devconnector#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the devconnector#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.bspBQ/_logs/2018-10-14T10_57_59_208Z-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: Verifying deploy...
remote:
remote: ! Push rejected to murmuring-depths-54253.

I also encountered this issue today and managed to fix it by removing /public folder from .gitignore.
Two things could be cause of this:
Probably you have /public directory specified inside your .gitignore
Case sensitive paths
more info at: https://create-react-app.dev/docs/deployment/#heroku

Possible Solution: Your file structure might be the issue
By chance do you have an 'api' folder next to your 'client' folder?
Heroku doesn't seem to play well with certain file structures (not sure why, I opened a ticket with them to inquire)
I was receiving almost the exact same error because I had most of my 'server' files within an api folder at the root.
After moving those files outside the api folder, removing my lock files, and reinstalling node modules, deployment went off without a hitch.
So, try the following:
Make sure that your file structure isn't conflicting with standard deployments (see screenshot below)
Remove your lock files and node_modules
Reinstall node_modules at root and in client
commit and and attempt another deploy -- let us know if that succeeds
As you can see, the only difference is the location of those folders within the api folder (obviously, import/require pathnames needed to be updated as well)
Failing Folder Structure
Successful Folder Structure

Related

The `npm ci` command can only install with an existing package-lock.json or remote npm-shrinkwrap.json with lockfileVersion >= 1

I made one tiny text change to an old(er) Node application which works as intended in my local development system, including the npm ci command, but it fails to deploy to Heroku with this error:
npm ERR! The `npm ci` command can only install with an existing package-lock.json or
remote npm-shrinkwrap.json with lockfileVersion >= 1
but I have a package-lock.json with:
"lockfileVersion": 2,
This application used to deploy just fine but it's been a year of two since the last deploy so I'm guessing this is some underlying issue with the Heroku deployment, perhaps with the updated build-packs. The application is currently using heroku-18 but it's trying to upgrade to heroku-22 in the same deploy.
I've tried different versions of Node and NPM though I can't go above Node 12 without making significant updates to this legacy application...which I'd r e a a a l l y like to avoid.
Any ideas on how to tickle this away?
Full Error
remote: Building source:
remote:
remote: -----> Building on the Heroku-22 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 15.3.0
remote: engines.npm (package.json): 7.0.14
remote:
remote: Resolving node version 15.3.0...
remote: Downloading and installing node 15.3.0...
remote: npm 7.0.14 already installed with node
remote:
remote: -----> Restoring cache
remote: Cached directories were not restored due to a change in version of node, npm, yarn or stack
remote: Module installation may take longer for this build
remote:
remote: -----> Prebuild
remote: Running heroku-prebuild
remote:
remote: > snazzywiz#2.1.1 heroku-prebuild
remote: > npm --global install pushstate-server#3.0.1; npm --global install #angular/cli
remote:
remote:
remote: added 44 packages, and audited 44 packages in 3s
remote:
remote: 10 vulnerabilities (5 low, 3 moderate, 2 high)
remote:
remote: To address issues that do not require attention, run:
remote: npm audit fix
remote:
remote: To address all issues, run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: added 209 packages, and audited 209 packages in 8s
remote:
remote: 25 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 0 vulnerabilities
remote: npm notice
remote: npm notice New major version of npm available! 7.0.14 -> 8.19.2
remote: npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.19.2>
remote: npm notice Run `npm install -g npm#8.19.2` to update!
remote: npm notice
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote: npm ERR! The `npm ci` command can only install with an existing package-lock.json or
remote: npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm#5 or
remote: npm ERR! later to generate a package-lock.json file, then try again.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.ULXke/_logs/2022-09-17T19_15_54_600Z-debug.log
remote:
remote: -----> Build failed
Note: There are several SO questions with the same "The npm ci command can only..." error message but triggered from different scenarios but none from just a deploy to Heroku.

Having a HARD time deploying my MERN stack app to Heroku

I've been following brad traversy's guide for hosting a full stack mern app ,
But after I run git push heroku master I keep getting this error :
$ git push heroku master
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 8 threads
Compressing objects: 100% (36/36), done.
Writing objects: 100% (39/39), 427.21 KiB | 8.06 MiB/s, done.
Total 39 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
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.20.1...
remote: Using default npm version: 6.14.10
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: > nodemon#2.0.6 postinstall /tmp/build_a03a558d/node_modules/node
mon
remote: > node bin/postinstall || exit 0
remote:
remote: Love nodemon? You can now support the project via the open collec
tive:
remote: > https://opencollective.com/nodemon/donate
remote:
remote: added 296 packages in 4.302s
remote:
remote: -----> Build
remote: Detected both "build" and "heroku-postbuild" scripts
remote: Running heroku-postbuild
remote:
remote: > server#1.0.0 heroku-postbuild /tmp/build_a03a558d
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && np
m run build --prefix frontend
remote:
remote: up to date in 0.241s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_a03a558d/frontend/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_a03a
558d/frontend/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.ZT0se/_logs/2021-01-26T16_52_50_692Z-debug.lo
g
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! server#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm
install --prefix frontend && npm run build --prefix frontend`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the server#1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additi
onal logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.ZT0se/_logs/2021-01-26T16_52_50_713Z-debug.lo
g
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common is
sues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploy
s
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 fathomless-thicket-55387.
remote:
To https://git.heroku.com/fathomless-thicket-55387.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/fathomless-thicket-55
387.git'
I have no clue why I get those error messages...
remote: npm ERR! path /tmp/build_a03a558d/frontend/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_a03a
558d/frontend/package.json'
You need to check
Whether you have package.json file in frontend folder. You can in git and see if it is there. It may be mentioned in gitignore.
Whether your heroku-postbuild runs from package.json (not the same package.json file you have in frontend folder) which is on the same level with folder frontend. Like this:
package.json
/frontend

Heroku deploy error - ! [remote rejected] master -> master (pre-receive hook declined)

I have seen many people get this error, and I've tried every solution I've seen suggested so far. Checking if Heroku knows what kind of app it is, removing .git file from my client folder and so on. In the error message, I can see it is having trouble finding the files, but I don't know how I'd fix this as I did git add -A and git add . numerous time. I am a beginning and I am not sure what I'm missing.
This is the error message when I do git push heroku master:
Counting objects: 100% (13/13), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (13/13), 13.79 KiB | 1009.00 KiB/s, done.
Total 13 (delta 0), 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.3...
remote: Using default npm version: 6.14.6
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote: added 131 packages in 5.646s
remote:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > mern_project#1.0.0 heroku-postbuild /tmp/build_07c4cff9
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote: up to date in 0.242s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_07c4cff9/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_07c4cff9/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.LOFwn/_logs/2020-08-28T19_01_14_938Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! mern_project#1.0.0 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 mern_project#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.LOFwn/_logs/2020-08-28T19_01_14_958Z-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 floating-island-87176.
remote:
To https://git.heroku.com/floating-island-87176.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/floating-island-87176.git'
Add engines in package.json file
"engines": {
"node": "16.13.0",
"npm": "8.1.0"
},
Then, change version of the package.json
"version":"1.2.1"
Then
git push heroku master
As found in this github issue it was an error with the git repo still thinking client was a submodule. The fix is to remove the client folder from git tracking and add it back as regular files:
git rm -f --cached client && git add . && git commit -m 'Add client folder back to git repo' && git push heroku master
This is what worked for me (The branch is based on 'origin/master', but the upstream might be gone.
(use "git branch --unset-upstream" to fixup))
git branch --unset-upstream

Error when deploying React project to Heroku: “no such file or directory” for package.json

I am new to Heroku and am facing problems pushing my code to Heroku. I have a React/Node JS project. My folder structure is as follows:
I had my package.json file initially under backend folder but due to buildpack error I moved it to the root folder.
When I try pushing code to Heroku I get the following error:
\ProductInventoryApp> git push heroku HEAD:master
Enumerating objects: 110, done.
Counting objects: 100% (110/110), done.
Delta compression using up to 8 threads
Compressing objects: 100% (107/107), done.
Writing objects: 100% (110/110), 425.50 KiB | 2.73 MiB/s, done.
Total 110 (delta 38), reused 0 (delta 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.14.1...
remote: Using default npm version: 6.13.4
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json + package-lock)
remote: added 161 packages from 100 contributors and audited 304 packages in 7.815s
remote:
remote: 2 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: > ProductInventoryApp#1.0.0 heroku-postbuild /tmp/build_e7c760dc5d523bf5e1c2d0dc2b5b85cf
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote: up to date in 0.524s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_e7c760dc5d523bf5e1c2d0dc2b5b85cf/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_e7c760dc5d523bf5e1c2d0dc2b5b85cf/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.HV3Sb/_logs/2020-01-12T03_23_13_871Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! ProductInventoryApp#1.0.0 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 ProductInventoryApp#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.HV3Sb/_logs/2020-01-12T03_23_13_887Z-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 product-inventory-app.
remote:
To https://git.heroku.com/product-inventory-app.git
**! [remote rejected] HEAD -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/product-inventory-app.git'**
I am not sure what’s causing this. My package.json file is as follows:
{
"name": "ProductInventoryApp",
"version": "1.0.0",
"description": "",
"main": "backend/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"client-install": "npm install --prefix client",
"server": "nodemon app.js",
"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"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-validator": "^6.3.0",
"mongodb": "^3.4.0",
"mongoose": "^5.8.0",
"uuid": "^3.3.3"
},
"devDependencies": {
"concurrently": "^4.0.1"
}
}
This is being caused by an issue with the heroku-postbuild script that you've defined. Remove it from the package.json file and redeploy to Heroku to resolve the issue.
try this.. it will help you out
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
basically, --prefix represents the path where react's package.json will exist... so, your react's package.json might be existed in frontend folder...
I've had the same problem until I've realised that my client/package.json was part of my .gitignore.
If you are using Visual Studio, it does automatically add your package to it when creating gitignore.
I was facing the same error of Heroku: “no such file or directory” but for a different problem.
In my case, I'm using docker and a docker-compose.yml with volumes to share volumes.
Heroku need instead of this file a heroku.yml which takes fewer options.
So it is needed to bring some changes to the Dockerfile (or make a copy specially for Heroku)
My docker-compose.yml file :
services:
web:
volumes:
- .:/usr/src/app
For my heroku.yml configuration, I set :
build:
docker:
web: Dockerfile.web
with a Dockerfile.web same as the original Dockerfile with the following difference :
...
ADD . /usr/src/app
...

Build fails on Nodejs (+ React) app deployment on Heroku

I build an app to practice react with a nodejs backend. It work fine on localhost. But I needed to learn how to deploy it on Heroku. I followed Stephen Grider's Udemy course and tried to hosted it on Heroku.
But my build fails. I checked many times and ran npm install even. But I can't get it working.
This is my package.json in server
{
"name": "react-movies",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm insall --prefix client && npm run build --prefix client"
},
"engines": {
"node": "8.9.4",
"npm": "5.7.1"
},
"author": "pankaja92",
"license": "ISC",
"dependencies": {
"concurrently": "^3.5.1",
"moviedb-promise": "^1.2.1",
"express": "^4.16.3",
"nodemon": "^1.17.2"
}
}
And this is the build error I'm getting.
Counting objects: 25, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (25/25), 5.50 KiB | 2.75 MiB/s, done.
Total 25 (delta 15), reused 0 (delta 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_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 8.9.4
remote: engines.npm (package.json): 5.7.1
remote:
remote: Resolving node version 8.9.4...
remote: Downloading and installing node 8.9.4...
remote: Bootstrapping npm 5.7.1 (replacing 5.6.0)...
remote: npm 5.7.1 installed
remote:
remote: -----> Restoring cache
remote: Skipping cache restore (new-signature)
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > nodemon#1.17.2 postinstall /tmp/build_ac7e6ff23b1b667ae4e3970742a18cc1/node_modules/nodemon
remote: > node -e "console.log('u001b[32mLove nodemon? You can now support the project via the open collective:u001b[22mu001b[39mn > u001b[96mu001b[1mhttps://opencollective.com/nodemon/donateu001b[0mn')" || 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 319 packages from 194 contributors in 7.977s
remote: Running heroku-postbuild
remote:
remote: > react-movies#1.0.0 heroku-postbuild /tmp/build_ac7e6ff23b1b667ae4e3970742a18cc1
remote: > NPM_CONFIG_PRODUCTION=false npm insall --prefix client && npm run build --prefix client
remote:
remote:
remote: Usage: npm <command>
remote:
remote: where <command> is one of:
remote: access, adduser, bin, bugs, c, cache, ci, completion,
remote: config, ddp, dedupe, deprecate, dist-tag, docs, doctor,
remote: edit, explore, get, help, help-search, i, init, install,
remote: install-test, it, link, list, ln, login, logout, ls,
remote: outdated, owner, pack, ping, prefix, profile, prune,
remote: publish, rb, rebuild, repo, restart, root, run, run-script,
remote: s, se, search, set, shrinkwrap, star, stars, start, stop, t,
remote: team, test, token, tst, un, uninstall, unpublish, unstar,
remote: up, update, v, version, view, whoami
remote:
remote: npm <command> -h quick help on <command>
remote: npm -l display full usage info
remote: npm help <term> search for help on <term>
remote: npm help npm involved overview
remote:
remote: Specify configs in the ini-formatted file:
remote: /app/.npmrc
remote: or on the command line via: npm <command> --key value
remote: Config info can be viewed via: npm help config
remote:
remote: npm#5.7.1 /tmp/build_ac7e6ff23b1b667ae4e3970742a18cc1/.heroku/node/lib/node_modules/npm
remote:
remote: Did you mean one of these?
remote: install
remote: uninstall
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! react-movies#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm insall --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the react-movies#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.31Mmf/_logs/2018-03-22T20_32_50_639Z-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: Verifying deploy...
remote:
remote: ! Push rejected to findthemovie.
remote:
What have I done wrong ? Why's my build is failing ?
Can anyone help me with this ?
Would put this as a comment but can't yet, check a spelling error in config file
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm insall --prefix client && npm run build --prefix client"
Ain't that supposed to be install?
npm install
> NPM_CONFIG_PRODUCTION=false npm insall --prefix client && npm run build --prefix client
should be
> NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
I believe there is a typo in your code.
It should be install instead of insall :
NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
add this code in server.js file
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "client/build")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}

Resources