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.
Related
Cannot for the life of me figure out what's stopping my app from deploying to Heroku (update). The relevant error logs and package.json sections are below. Some things I've tried are updating and de-updating all my packages, adding engine specifications for node and npm to the package.json, removing a few packages to see if they were interfering (the first time it failed there was error message about TipTap, a WYSIWYG editor on my app, also one attempt indicated it might be Tailwind), and I've deleted and reinstalled the node modules and package-lock files.
Heroku activity log:
...
remote: > bufferutil#4.0.7 install /tmp/build_c2557cec/client/node_modules/react-scripts/node_modules/webpack-plugin-serve/node_modules/bufferutil
remote: > node-gyp-build
remote:
remote: npm ERR! Linux 4.4.0-1104-aws
remote: npm ERR! argv "/tmp/build_c2557cec/.heroku/node/bin/node" "/tmp/build_c2557cec/node_modules/.bin/npm" "install"
remote: npm ERR! node v19.5.0
remote: npm ERR! npm v2.15.12
remote: npm ERR! path /tmp/build_c2557cec/client/node_modules/tailwindcss/node_modules/#types/node/package.json
remote: npm ERR! code ENOTDIR
remote: npm ERR! errno -20
remote: npm ERR! syscall open
remote:
remote: npm ERR! ENOTDIR: not a directory, open '/tmp/build_c2557cec/client/node_modules/tailwindcss/node_modules/#types/node/package.json'
...
My package.json engines and dependences:
...
"engines": {
"node": "19.x",
"npm": "8.x"
},
"private": false,
"dependencies": {
"#emailjs/browser": "^3.7.0",
"autoprefixer": "^10.4.7",
"axios": "^0.27.2",
"html-react-parser": "^3.0.4",
"postcss": "^8.4.14",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "^4.4.0",
"react-paginate": "^8.1.3",
"react-router-dom": "^6.7.0",
"react-scripts": "^5.0.1",
"tailwindcss": "^3.1.6"
},
...
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.
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!
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
I'm trying to deploy my Azure AppService. The application is written using TypeScript (both server and client). When deploying everything works ok until it's installing gulp-typescript. This is used to transpile TypeScript code as part of postinstall script.
Package.json:
{
"name": "test-webapp",
"version": "1.0.0",
"description": "Test Application",
"engines": {
"node": "4.4.6"
},
"main": "server.js",
"scripts": {
"start": "node server/server.js",
"typings": "typings",
"postinstall": "node node_modules/bower/bin/bower install && npm run typings install && node node_modules/gulp/bin/gulp.js ts-compile"
},
"author": {
"name": "liskaj",
"email": ""
},
"dependencies": {
"body-parser": "^1.15.2",
"bower": "^1.7.9",
"cors": "^2.7.1",
"express": "^4.14.0",
"express-session": "^1.14.0",
"gulp": "^3.9.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "^2.13.6",
"request": "^2.73.0",
"typescript": "^1.8.10",
"typings": "^1.3.2",
"winston": "^2.2.0"
}
}
Azure log output:
remote: npm ERR! node v4.4.6
remote: npm ERR! npm v2.15.5
remote: npm ERR! path D:\home\site\wwwroot\node_modules\gulp-typescript\node_modules\vinyl-fs\node_modules\globstream\node_modules\micromatch\node_modules\braces\node_modules\expand-range\node_modules\fill-range\node_modules\isobject\node_modules\isarray\package.json.3240780430
remote: npm ERR! code EINVAL
remote: npm ERR! errno -4071
remote: npm ERR! syscall rename
remote:
remote: npm ERR! EINVAL: invalid argument, rename 'D:\home\site\wwwroot\node_modules\gulp-typescript\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\micromatch\node_modules\braces\node_modules\expand-range\node_modules\fill-range\node_modules\isobject\node_modules\isarray\package.json.3240780430' -> 'D:\home\site\wwwroot\node_modules\gulp-typescript\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\micromatch\node_modules\braces\node_modules\expand-range\node_modules\fill-range\node_modules\isobject\node_modules\isarray\package.json
This works fine locally (Windows 7 + Windows 10) and also on Heroku.