I am trying to deploy my MERN web application to Heroku, but I have been getting this error:
remote: sh: 1: run: not found
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! syscall spawn
remote: npm ERR! file sh
remote: npm ERR! errno ENOENT
remote: npm ERR! reach-app#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install npm && run build`
remote: npm ERR! spawn ENOENT
remote: npm ERR!
remote: npm ERR! Failed at the reach-app#1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
In terms of my structure, I have two directories in my root directory, called client and backend. Both of these directories each have their own package.json. I also initlialised git and another npm in the root directory. So, could it possibly be a problem with my file structure?
It doesn't seem like there are any other similar questions out there, so any help would be greatly appreciated. Thanks
EDIT:
This is my package.json in my root directory:
{
"name": "reach-app",
"version": "1.0.0",
"description": "Initialised npm for the root directory.",
"main": "index.js",
"scripts": {
"start": "node backend/server/index.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install && npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"example",
"heroku"
],
"author": "Phillip La",
"license": "ISC",
"engines": {
"node": "12.16.2"
}
}
Related
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
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.
Answers to similar questions here and here do not resolve my issue.
In an empty directory I create a file 'server.js' all it does is a console.log('hello'). Running this file with "node server.js" runs fine. But after "npm init -y" running through "npm start" gives:
npm start
The system cannot find the path specified.
> prj#1.0.0 start E:\projects\prj
> node server.js
/bin/bash: node: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file bash
npm ERR! errno ENOENT
npm ERR! prj#1.0.0 start: `node server.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the prj#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
The detailed logfile reports correct versions of npm and node. And all of this is after an uninstall/reinstall of node.js.
Any hints on how to troubleshoot/fix appreciated.
project directory:
E:\prj
package.json
package-lock.json
server.js
package.json is the default after npm init:
{
"name": "prj",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
I have installed Node v12.10.0, NPM v6.10.3. I have also tried to install the node LTS version as well.
I built my project directory and inside the directory I ran "npm init" and after I ran "npm install --save-dev node-sass". Everything seems good up to this point.
my package.json file looks like this
{
"name": "dashboard",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"scss": "node-sass --watch scss -o css"
},
"author": "",
"license": "ISC",
"devDependencies": {
"node-sass": "^4.12.0"
}
}
After I go to run " npm run scss" then I receive this.
> dashboard#1.0.0 scss /Users/adakaitalker/Documents/school/dev/learning/2-september/4-week/9:13:19/dashboard
> node-sass --watch scss -o css
sh: node-sass: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! dashboard#1.0.0 scss: `node-sass --watch scss -o css`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the dashboard#1.0.0 scss 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! /Users/adakaitalker/.npm/_logs/2019-09-13T22_43_56_711Z-debug.log
figured it out. I installed homebrew and linked it to node then I used homebrew to uninstall it and reinstall it and it works now.
I'm trying to install NPM dependencies from a private GitLab instence.
So, I have my repo with basic files
And I added this dependencie in the package.json on my project
"node-demo-package": "https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git"
But, when I run npm install, I receive this error message:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: node-demo-package#https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T15_05_49_456Z-debug.log
Which I don't understand as there is a package.json as showed in the screenshot.
Here it is
{
"name": "demo-package",
"version": "1.0.0",
"description": "Test pasckage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git#gitlab.fullurl.git"
},
"author": "Arnaud Delante",
"license": "MIT"
}
I already tried switching https by git+https but I get another error
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git
npm ERR!
npm ERR! remote: You are not allowed to download code from this project.
npm ERR! fatal: unable to access 'https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T17_19_16_677Z-debug.log
Which is weird because the token is correct.
Would you have any idea?
In package.json try to replace https:// by git+https://
doc : https://docs.npmjs.com/files/package.json#git-urls-as-dependencies