Struggling to deploy my react project to heroku due to this `remote: sh: 1: react-scripts: Permission denied error` - node.js

I know that this answer has been asked in the past but I could not find a solution that pertains to my case. I've tried reinstalling my node_modules and my package-lock files, I've made sure that my .gitignore file properly excludes node_modules from the build. I'm not entirely sure what's going wrong when I try to deploy. I've been working on this for a couple of days, trying to diagnose the issue to no avail. So I figured that I'd try here. I am using a server-client setup wherein I have separate package files for my server-side code and my client-side code. Here are the package files, my gitignore file and
the error log from the heroku build session:
CLIENT PACKAGE.JSON
{
"name": "lang-flash",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:5000",
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"faker": "^4.1.0",
"firebase": "^7.14.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.4.1",
"stripe": "^8.39.2"
},
"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"
]
}
}
SERVER PACKAGE.JSON
{
"name": "lang-flash",
"version": "1.0.0",
"engines": {
"node": "12.16.1",
"npm": "6.13.4"
},
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"client": "cd client && npm start",
"server": "nodemon server.js",
"build": "cd client && npm run build",
"dev": "concurrently --kill-other-on-fail \"npm server\" \"npm client\"",
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/7ujh6/LangFlashApp.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/7ujh6/LangFlashApp.git/issues"
},
"devDependencies": {
"concurrently": "^5.1.0",
"nodemon": "^2.0.3"
},
"homepage": "https://github.com/7ujh6/LangFlashApp.git#readme",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "8.2.0",
"express": "^4.17.1"
}
}
GIT IGNORE FILE (in the server directory there isn't another git ignore file in the client directory)
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
HEROKU BUILD LOG
remote: -----> Build
remote: Detected both "build" and "heroku-postbuild" scripts
remote: Running heroku-postbuild
remote:
remote: > lang-flash#1.0.0 heroku-postbuild /tmp/build_fcc986a2385b8c8783c9e93e3af2bd41
remote: > cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build
remote:
remote: audited 1748 packages in 13.332s
remote:
remote: 59 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 2 vulnerabilities (1 low, 1 high)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote: audited 1748 packages in 11.758s
remote:
remote: 59 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 2 vulnerabilities (1 low, 1 high)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: > lang-flash#0.1.0 build /tmp/build_fcc986a2385b8c8783c9e93e3af2bd41/client
remote: > react-scripts build
remote:
remote: sh: 1: react-scripts: Permission denied
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! lang-flash#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the lang-flash#0.1.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.jCutB/_logs/2020-05-14T22_31_39_955Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! lang-flash#1.0.0 heroku-postbuild: `cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the lang-flash#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.jCutB/_logs/2020-05-14T22_31_39_969Z-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 React.js (create-react-app) multi app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to lang-flash.
remote:
To https://git.heroku.com/lang-flash.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/lang-flash.git'
Edit: I forgot to mention that it appears that my react scripts file has full permissions:

hey have you found the answer yet?
I tried:
if (process.env.NODE_ENV === "production"){
app.use(express.static(path.join(__dirname,"client", "build")))
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname,"client", "build", "index.html"));
});
}
and i have to npm install react-scripts in the server package.json file.
Also you have to put the "proxy": "http://localhost:5000" at the last curly brace in client package.json file. That proxy is the server port.
It works for me!

Related

Heroku Deployment SassError: File to import not found or unreadable. Works fine locally

Attempting to deploy to heroku for the first time, and i've been getting this sasserror which causes the build to fail and reject.
Steps taken for resolution
Delete node sass and node modules / reinstall / push to master repo
Adjust import path to #import './scss/_variables.scss';
Delete the first import to check if that file was the issue
Update node to support node-sass compatibility
Question
Create React App has webpack built internally, do i need to add my own webpack config for sass-loaders, css-loaders, style-loaders?
i've only ever used webpack with rails before, if i do need webpack, for my output params, what should replace the "bundle.js" i get from rails?
Terminal response
remote:
remote: -----> Building on the Heroku-20 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): 10.x
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 10.x...
remote: Downloading and installing node 10.24.1...
remote: Using default npm version: 6.14.12
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: > nodemon#2.0.4 postinstall /tmp/build_f7e8f26d/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 358 packages in 10.306s
remote:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > server#1.0.0 heroku-postbuild /tmp/build_f7e8f26d
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:
remote: > node-sass#6.0.0 install /tmp/build_f7e8f26d/client/node_modules/node-sass
remote: > node scripts/install.js
remote:
remote: Downloading binary from https://github.com/sass/node-sass/releases/download/v6.0.0/linux-x64-64_binding.node
remote: Download complete
remote: Binary saved to /tmp/build_f7e8f26d/client/node_modules/node-sass/vendor/linux-x64-64/binding.node
remote: Caching binary to /tmp/npmcache.gWg6N/node-sass/6.0.0/linux-x64-64_binding.node
remote:
remote: > core-js#2.6.12 postinstall /tmp/build_f7e8f26d/client/node_modules/babel-runtime/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js#3.12.1 postinstall /tmp/build_f7e8f26d/client/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js-pure#3.12.1 postinstall /tmp/build_f7e8f26d/client/node_modules/core-js-pure
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > ejs#2.7.4 postinstall /tmp/build_f7e8f26d/client/node_modules/ejs
remote: > node ./postinstall.js
remote:
remote:
remote: > node-sass#6.0.0 postinstall /tmp/build_f7e8f26d/client/node_modules/node-sass
remote: > node scripts/build.js
remote:
remote: Binary found at /tmp/build_f7e8f26d/client/node_modules/node-sass/vendor/linux-x64-64/binding.node
remote: Testing binary
remote: Binary is fine
remote: added 2124 packages from 812 contributors and audited 2131 packages in 43.95s
remote:
remote: 139 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 81 vulnerabilities (80 moderate, 1 high)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: > client#0.1.0 build /tmp/build_f7e8f26d/client
remote: > react-scripts build
remote:
remote: Creating an optimized production build...
remote: Failed to compile.
remote:
remote: ./src/App.scss
remote: SassError: File to import not found or unreadable: ./scss/_variables.scss.
remote: on line 2 of src/App.scss
remote: >> #import './scss/_variables.scss';
remote:
remote: ^
remote:
remote:
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 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.gWg6N/_logs/2021-05-25T08_12_53_624Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! server#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 server#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.gWg6N/_logs/2021-05-25T08_12_53_642Z-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
App.scss
// Abstracts
#import 'scss/variables';
#import 'scss/mixins';
// Base
#import 'scss/globals';
// Components
#import 'scss/header';
#import 'scss/showcase';
#import 'scss/hero';
#import 'scss/feature';
#import 'scss/postLanding';
#import 'scss/footer';
#import 'scss/auth';
#import 'scss/postList';
...etc
client package json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.21.1",
"cra-template": "1.0.3",
"moment": "^2.29.1",
"node-sass": "^6.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^6.1.0",
"react-moment": "^1.0.0",
"react-redux": "^7.2.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"uuid": "^8.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://127.0.0.1:5000",
"secure": false,
"devDependencies": {}
}
server package json
{
"name": "server",
"version": "1.0.0",
"description": "jounii",
"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"
},
"author": "Andrew Huang",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.771.0",
"axios": "^0.21.1",
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"concurrently": "^5.3.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-async-handler": "^1.1.4",
"faker": "^5.1.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"mongoose": "^5.12.3",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"multer-s3": "^2.9.0",
"node-geocoder": "^3.27.0",
"nodemailer": "^6.6.0",
"request": "^2.88.2"
},
"devDependencies": {
"nodemon": "^2.0.4"
},
"engines": {
"node": "10.x"
}
}
File tree
enter image description here
Try this:
https://create-react-app.dev/docs/adding-a-sass-stylesheet
f you set SASS_PATH=node_modules:src, this will allow you to do imports like
#import 'styles/colors'; // assuming a styles directory under src/, where _colors.scss partial file exists.
#import 'nprogress/nprogress'; // importing a css file from the nprogress node module

MERN app depolying to Heroku - package.json not found

I'm trying to use the Heroku CLI to get a MERN app online. The app works perfectly locally but when I try to use git to push the app onto Heroku I get the following error message:
remote: Running heroku-postbuild
remote:
remote: > exercise-logger#1.0.0 heroku-postbuild /tmp/build_431a136c
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix exercise-logger && npm run build --prefix exercise-logger
remote:
remote: up to date in 0.22s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_431a136c/exercise-logger/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_431a136c/exercise-logger/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.yesMz/_logs/2021-05-30T17_32_30_947Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! exercise-logger#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix exercise-logger && npm run build --prefix exercise-logger`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the exercise-logger#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.yesMz/_logs/2021-05-30T17_32_30_973Z-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_modules checked into source control
remote: https://devcenter.heroku.com/articles/node-best-practices#only-git-the-important-bits
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: !
The thrust of it seems to be that it can't find the root package.json file, even though it's definitely there. In fact, here it is:
"name": "exercise-logger",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"axios": "^0.21.1",
"bcrypt": "^5.0.1",
"concurrently": "^6.0.2",
"config": "^3.3.6",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-validator": "^6.10.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.12.3"
},
"devDependencies": {},
"scripts": {
"start": "node server.js",
"build": "cd client && npm run build",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"clientinstall": "npm install --prefix client",
"dev": "concurrently \"npm run start\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"engines": {
"node": "14.x",
"npm": "6.x"
},
"author": "",
"license": "ISC"
}
I have tried what seems to be a common fix which is manually deleting the .git folder in the directory for the React app but doesn't seem to have fixed it.
The whole code is on Github here.
Can anyone help? I've been working on this project for quite a while so it's really frustrating to fall at the final hurdle like this. I've not really done anything like this before so not really sure where to start troubleshooting!
Thanks

Can't figue out my Deploying issue (MERN App to Heroku)

This is my prompt lines once I try to push: (There are two backend errors and a client one)
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! suripanta#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the suripanta#0.1.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.tBESZ/_logs/2020-08-09T21_38_02_253Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! backend#1.0.0 build: `cd client && npm run build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the backend#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.tBESZ/_logs/2020-08-09T21_38_02_269Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! backend#1.0.0 heroku-postbuild: `npm run install-client && npm run build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the backend#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.tBESZ/_logs/2020-08-09T21_38_02_286Z-debug.log
remote:
remote: -----> Build failed
And here are my package.json for each one:
client:
{
"name": "suripanta",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/icons": "^4.9.1",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"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"
]
}
}
Backed ( server named index.js)
{
"name": "backend",
"version": "1.0.0",
"description": "Backend para las notas de mi sister",
"main": "index.js",
"scripts": {
"start":"nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "cd client && npm run build",
"install-client":"cd client && npm install",
"heroku-postbuild":"npm run install-client && npm run build"
},
"engines": {
"node": "12.18.1",
"npm": "6.14.5"
},
"author": "RichterBelmont DevStudio",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"connect-multiparty": "^2.2.0",
"express": "^4.17.1",
"mongoose": "^5.9.25",
"validator": "^13.1.1"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
Also my index.js from backend:
'use strict'
//cargo el mongoose
var mongoose=require('mongoose');
const mongodb_uri_atlas_cluster='mongodb+srv://xxxxx:xxxxx#clusterxxxxx.lw1xj.mongodb.net/<dbname>?retryWrites=true&w=majority';
mongoose.set('useFindAndModify',false);
mongoose.Promise=global.Promise;
var app=require('./App');
var port=process.env.port || 3900; //primer cambio
//conexión a mongodb
/*
mongoose.connect(mongodb_uri_atlas_cluster || 'mongodb://localhost:27017/suripanta_rest',{useNewUrlParser:true})
.then(()=>{
//acá ya me conecté a mongodb
console.log("conexión a bd se ha realiazo bien! Me voy para arriba");
//Crear servidor y escuchar peticiones http
app.listen(3900,()=>{
console.log('Servidor corriendo correctamente en http://localhost:'+port);
})
})
*/
mongoose.connect(process.env.mongodb_uri_atlas_cluster || 'mongodb://localhost:27017/suripanta_rest',{useNewUrlParser:true})
.then(()=>{
//acá ya me conecté a mongodb
console.log("conexión a bd se ha realiazo bien! Me voy para arriba");
if(process.env.NODE_ENV== 'production'){
app.use(express.static('client/build'));
}
//Crear servidor y escuchar peticiones http
app.listen(3900,()=>{
console.log('Servidor corriendo correctamente en http://localhost:'+port);
})
})
I think it is a silly detail which I am missing. I am brand new on deploying mern app and I've followed different tutorials since there's not a lot of information on how to for heroku.
Thanks in advance!!!
I had similar issue with one of my project, in which both front-end and back-end are under the same root directory. Here is how my project is organized:
myproject
|----- client
| | ---- build
| | ---- package.json
|----- server
| | ---- package.json
| | ---- index.js
|----- index.js
|----- package.json
I use the index.js under root folder to serve both the front-end(build folder) and the server in server folder. Beside that, I have three different package.json files, one for front-end, one for back-end and one for the overall project.
In order to make it work on Heroku. I have to specify all the build command in package.json under root folder, specially the npm install command.
Following is my build command as an example:
"scripts": {
"start": "node index.js",
"build": "cd client && npm install && npm run build && cd ../server && npm install"
},
As Heroku will only execute npm install under root folder by default, the client folder and server folder will not have the dependencies installed. In above command I can ask Heroku to execute the commands between && one by one so no dependencies will be missing and it also knows how to serve the app. Your build command might look a little different while the idea is the same.
My repo here FYR.

Heroku engines.node (package.json) unspecified

I'm having a problem with pushing my codes to Heroku.
package.json
{
"name": "my-app",
"version": "0.1.0",
"engine": {
"node": "12.16.2",
"npm": "6.13.4"
},
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"bcrypt": "^4.0.1",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.4.20",
"nodemon": "^2.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "node server/index.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"backend": "nodemon server/index.js"
},
"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"
]
}
}
output
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.16.1...
remote: Using default npm version: 6.13.4
<!-- more stuff -->
remote: -----> Build
remote: Running build
remote:
remote: > my-app#0.1.0 build /tmp/build_016788c07037e47ee5638bf5c1b1f631
remote: > react-scripts build
remote:
remote: Could not find a required file.
remote: Name: index.html
remote: Searched in: /tmp/build_016788c07037e47ee5638bf5c1b1f631/public
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! my-app#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the my-app#0.1.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.yXjxR/_logs/2020-04-11T07_16_57_245Z-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
As you can see even though I specified my node and npm version in package.json Heroku is not recognising it and my push is rejected. I tried to make a ticket on the Heroku website but since this is a free application they did not allow me to ask on their helpline.
edit
I upgraded the npm and node version to the default by Heroku but I get the error Could not find a required file.Name: index.html
I had the same issue. Looks like Heroku doesn't support 12.16.2 yet. try with 12.16.1 in package.json engine section.
change this
"engine": {
"node": "12.16.2",
"npm": "6.13.4"
},
to
"engines": {
"node": "12.16.1",
"npm": "6.14.4"
},
For deploying your app successfully. You should first create a specific file inside the root of your project's folder and the name of that file must be.
Procfile
without any extra extension. the content of Procfile file must be web: node index.js or whatever your main file is. don't use web: node run index.js just web: node index.js is ok.
my package.json didnt have
"engines" specified
adding
"engines": { "node": "12.16.1", "npm": "6.14.4" },
in my package.json fixed it

Error while trying to deploy React app to Heroku

I'm keep getting the following error when I'm trying to deploy to heroku:
remote: sh: 1: react-scripts: Permission denied
The app compiles and workes well locally, so i'm pretty sure it's something with the deployment settings.
I can't understand what's wrong... here is my nodejs server package.json:
{
"name": "app-server",
"version": "1.0.0",
"description": "Create-react-app with Express",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "Roy",
"license": "ISC",
"dependencies": {
"axios": "^0.19.0",
"cors": "^2.8.4",
"dotenv": "^8.1.0",
"express": "^4.16.3"
},
"engines": {
"node": "10.5.0"
}
}
And here is my client package.json
{
"name": "client",
"version": "0.1.0",
"private": false,
"dependencies": {
"#material-ui/core": "^4.4.1",
"axios": "^0.19.0",
"color-temperature": "^0.2.7",
"concurrently": "^4.1.2",
"cors": "^2.8.5",
"downshift": "^3.2.14",
"express": "^4.17.1",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"path": "^0.12.7",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-md": "^1.12.3",
"react-moment": "^0.9.2",
"react-redux": "^7.0.2",
"react-reveal": "^1.2.2",
"react-router-dom": "^5.0.0",
"react-scripts": "2.1.8",
"react-toastify": "^5.3.2",
"reactstrap": "^8.0.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000"
}
And here is the full error
remote: sh: 1: react-scripts: Permission denied
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! client#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the client#0.1.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.cG6aC/_logs/2019-09-20T12_27_39_563Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! weather-app-server#1.0.0 heroku-postbuild: `cd client && npm install && npm run
build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the weather-app-server#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.cG6aC/_logs/2019-09-20T12_27_39_576Z-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
Have you ignored node modules?
Have you checked that all module installations were correct without errors?
In your client package.json the proxy is localhost. Try to replace it with your backend url.

Resources