I'm having trouble viewing my Node/Express + React project in Heroku. After successfully pushing my project to Heroku, I get a 404 error page when I try to view my app in heroku.
Heroku Logs shows that the concurrently package was not found
I was wondering if anyone can help me figure out why?
Everything works locally. No issues.
I haven't been able to find any solutions. I've tried this:
https://github.com/RickWong/react-isomorphic-starterkit/issues/12
I tried setting an environment variable in heroku with the following suggestion:
heroku config:set NPM_CONFIG_PRODUCTION=false
However, it did not work.
I also found this:
https://github.com/rickbergfalk/sqlpad/issues/359
I've attempted re-installing concurrently twice, in the server folder, as well as in root. But with each instance, I got the same error telling me that concurrently was not found.
Here is the Heroku log:
2019-01-05T04:44:42.843348+00:00 heroku[web.1]: Starting process with command `npm start`
2019-01-05T04:44:45.795355+00:00 heroku[web.1]: Process exited with status 1
2019-01-05T04:44:45.817371+00:00 heroku[web.1]: State changed from starting to crashed
2019-01-05T04:44:45.825275+00:00 heroku[web.1]: State changed from crashed to starting
2019-01-05T04:44:45.691080+00:00 app[web.1]:
2019-01-05T04:44:45.691107+00:00 app[web.1]: > hello_fullstack#1.0.0 start /app
2019-01-05T04:44:45.691110+00:00 app[web.1]: > concurrently -- kill-others "npm run server" "npm run client"
2019-01-05T04:44:45.691112+00:00 app[web.1]:
2019-01-05T04:44:45.699841+00:00 app[web.1]: sh: 1: concurrently: not found
2019-01-05T04:44:45.704281+00:00 app[web.1]: npm ERR! file sh
2019-01-05T04:44:45.704664+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-01-05T04:44:45.704985+00:00 app[web.1]: npm ERR! errno ENOENT
2019-01-05T04:44:45.705300+00:00 app[web.1]: npm ERR! syscall spawn
2019-01-05T04:44:45.706913+00:00 app[web.1]: npm ERR! hello_fullstack#1.0.0 start: `concurrently -- kill-others "npm run server" "npm run client"`
2019-01-05T04:44:45.707140+00:00 app[web.1]: npm ERR! spawn ENOENT
2019-01-05T04:44:45.707475+00:00 app[web.1]: npm ERR!
2019-01-05T04:44:45.707708+00:00 app[web.1]: npm ERR! Failed at the hello_fullstack#1.0.0 start script.
2019-01-05T04:44:45.708000+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-01-05T04:44:45.718125+00:00 app[web.1]:
2019-01-05T04:44:45.718481+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-01-05T04:44:45.718674+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-01-05T04_44_45_709Z-debug.log
Any suggestions?
(Not sure this matters, but my dev environment is in ubuntu, which I'm running inside virtualbox; host os is Windows 8)
I found a solution to my problem.
After struggling with it, I decided to just start over and build a sample react/express app, and see if I could deploy it to heroku. Upon successfully deploying, I compared the code from my sample app and my broken app. It then occurred to me that perhaps the issue was with the commands that I assigned to the heroku-postbuild script in the package.json file of my root folder.
Previously, I had this junk:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
I changed that to this:
"heroku-postbuild": "cd client && npm install && npm run build"
And, like magic, it worked! I guess I wasn't "building" what I was supposed to build on the heroku side.
Related
I decided to implement a secret management service (secrethub.io) for a node.js server hosted by Heroku.
Its install process goes something like:
npm install --save-dev #secrethub/cli
secrethub init
(then a credential is given once you signup)
then you adjust main start script to:
secrethub run -- nodemon server.js
now when i run the app locally with npm run start everything is fine, server runs as it should, secrets are injected, all is good. but when i deploy to Heroku, the app crashes immediately on the start script:
server#1.0.0 start /app 2020-09-28T22:42:08.353088+00:00
app[web.1]: > secrethub run -- nodemon server.js
2020-09-28T22:42:08.353088+00:00 app[web.1]:
2020-09-28T22:42:08.469775+00:00 app[web.1]: Encountered an error:
error while processing template file 'secrethub.env': could not find
credential file. Go to https://signup.secrethub.io/ to create an
account or run secrethub init to use an already existing account on
this machine. (secrethub.credential_not_exist)
(run.template_parsing_failed) 2020-09-28T22:42:08.484159+00:00
app[web.1]: npm ERR! code ELIFECYCLE 2020-09-28T22:42:08.484663+00:00
app[web.1]: npm ERR! errno 1 2020-09-28T22:42:08.493367+00:00
app[web.1]: npm ERR! aflare-stripe#1.0.0 start: secrethub run -- nodemon server.js 2020-09-28T22:42:08.493885+00:00 app[web.1]: npm
ERR! Exit status 1 2020-09-28T22:42:08.494399+00:00 app[web.1]: npm
ERR! 2020-09-28T22:42:08.494840+00:00 app[web.1]: npm ERR! Failed at
the aflare-stripe#1.0.0 start script. 2020-09-28T22:42:08.495292+00:00
app[web.1]: npm ERR! This is probably not a problem with npm. There is
likely additional logging output above.
2020-09-28T22:42:08.515466+00:00 app[web.1]:
2020-09-28T22:42:08.516772+00:00 app[web.1]: npm ERR! A complete log
of this run can be found in: 2020-09-28T22:42:08.517179+00:00
app[web.1]: npm ERR!
/app/.npm/_logs/2020-09-28T22_42_08_498Z-debug.log
like i said I've already signed up and everything. Anyone know of any issues deploying to Heroku and using secret management services?
Judging from the following part of the log, it looks like the SecretHub CLI does not have access to a credential:
could not find credential file. Go to https://signup.secrethub.io/ to create an account or run secrethub init to use an already existing account on this machine. (secrethub.credential_not_exist)
You can solve this, by creating a service account for your Heroku app. You can follow this guide to see how. You can configure the resulting credential as the SECRETHUB_CREDENTIAL environment variable in Heroku (see here how).
I am doing a nodejs course and am not able to deploy app to heroku. The App stack is nodejs, express, mongodb.
The Problem
I am getting a Process exited with status 1 from heroku after pushing my code.
Here is my app configuration for connecting to database.
module.exports=function(){
let db = config.get('db');
if(process.env.NODE_ENV === 'production'){
db = process.env.MONGODB_URI;
}
mongoose.connect(db)
.then(() => winston.info(`Connected to ${db}...`));
}
my config vars in heroku
MONGODB_URI mongodb+srv://vidlyuser:password#cluster0-b8ezs.mongodb.net/test?retryWrites=true&w=majority
NODE_ENV production
NPM_CONFIG_LOGLEVEL verbose
My greatest challenge is that heroku error logs are not as helpful.
State changed from starting to crashed
Process exited with status 1
heroku logs --tail
2020-03-23T07:10:56.519157+00:00 app[web.1]: npm ERR! Failed at the vidly#1.0.0 start script.
2020-03-23T07:10:56.519289+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-03-23T07:10:56.519715+00:00 app[web.1]: npm verb exit [ 1, true ]
2020-03-23T07:10:56.533850+00:00 app[web.1]: npm timing npm Completed in 1161ms
2020-03-23T07:10:56.534215+00:00 app[web.1]:
2020-03-23T07:10:56.534554+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-03-23T07:10:56.534856+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-03-23T07_10_56_520Z-debug.log
2020-03-23T07:10:56.609864+00:00 heroku[web.1]: State changed from starting to crashed
2020-03-23T07:10:56.592043+00:00 heroku[web.1]: Process exited with status 1
Followed Heroku Node.js app "Process exited with status 1" and error h10. But no change.
this npm ERR! code ELIFECYCLE didnt help either
I think you need to remove the original env file and redo it
heroku config:set MONGODB_URI=mongodb+srv://vidlyuser:password#cluster0-b8ezs.mongodb.net/test?retryWrites=true&w=majority
heroku config:set NPM_CONFIG_LOGLEVEL=verbose
In my effort to fix this issue i learnt that i miss understood the error. i learnt The error npm ERR! Failed at the vidly#1.0.0 start script. usually points to an underlying error. making use of exception logging in my code i was able to discover the actual error and this had to do with a particular npm package.
The solution is npm ERR! Failed at the vidly#1.0.0 start script. usually points to another error.
I'm deploying my node app to Heroku and it's trying to invoke it with nodemon rather than the node app.js I have defined. my package.json(partial) looks like:
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": "7.9.0"
},
when I run heroku logs I get
2018-02-22T22:41:44.798831+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-22T22:41:47.235623+00:00 app[web.1]:
2018-02-22T22:41:47.235654+00:00 app[web.1]: > api-barber-app#1.0.0 start /app
2018-02-22T22:41:47.235657+00:00 app[web.1]: > nodemon app.js
2018-02-22T22:41:47.235659+00:00 app[web.1]:
2018-02-22T22:41:47.247464+00:00 app[web.1]: sh: 1: nodemon: not found
2018-02-22T22:41:47.253052+00:00 app[web.1]: npm ERR! file sh
2018-02-22T22:41:47.253319+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-02-22T22:41:47.253543+00:00 app[web.1]: npm ERR! errno ENOENT
2018-02-22T22:41:47.253787+00:00 app[web.1]: npm ERR! syscall spawn
2018-02-22T22:41:47.254995+00:00 app[web.1]: npm ERR! api-barber-app#1.0.0 start: `nodemon app.js`
2018-02-22T22:41:47.255145+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-02-22T22:41:47.255420+00:00 app[web.1]: npm ERR!
2018-02-22T22:41:47.255617+00:00 app[web.1]: npm ERR! Failed at the api-barber-app#1.0.0 start script.
2018-02-22T22:41:47.255793+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-02-22T22:41:47.269400+00:00 app[web.1]:
2018-02-22T22:41:47.269715+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-02-22T22:41:47.269916+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-02-22T22_41_47_261Z-debug.log
2018-02-22T22:41:47.348415+00:00 heroku[web.1]: Process exited with status 1
2018-02-22T22:41:47.467170+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-22T22:41:47.475956+00:00 heroku[web.1]: State changed from crashed to starting
2018-02-22T22:41:51.465439+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-22T22:41:54.918389+00:00 heroku[web.1]: Process exited with status 1
2018-02-22T22:41:54.679566+00:00 app[web.1]:
2018-02-22T22:41:54.679592+00:00 app[web.1]: > api-barber-app#1.0.0 start /app
2018-02-22T22:41:54.679594+00:00 app[web.1]: > nodemon app.js
2018-02-22T22:41:54.679596+00:00 app[web.1]:
2018-02-22T22:41:54.711632+00:00 app[web.1]: sh: 1: nodemon: not found
2018-02-22T22:41:54.759423+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-02-22T22:41:54.757722+00:00 app[web.1]: npm ERR! file sh
2018-02-22T22:41:54.761226+00:00 app[web.1]: npm ERR! syscall spawn
2018-02-22T22:41:54.760427+00:00 app[web.1]: npm ERR! errno ENOENT
2018-02-22T22:41:54.768513+00:00 app[web.1]: npm ERR! api-barber-app#1.0.0 start: `nodemon app.js`
2018-02-22T22:41:54.768637+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-02-22T22:41:54.768942+00:00 app[web.1]: npm ERR!
2018-02-22T22:41:54.769147+00:00 app[web.1]: npm ERR! Failed at the api-barber-app#1.0.0 start script.
2018-02-22T22:41:54.769369+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-02-22T22:41:54.825892+00:00 app[web.1]:
2018-02-22T22:41:54.826567+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-02-22T22:41:54.827196+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-02-22T22_41_54_816Z-debug.log
2018-02-22T22:41:54.934234+00:00 heroku[web.1]: State changed from starting to crashed
it try to run nodemon (what I had before) instead of node.js.
then when I push heroku it crash and not let me upload it right way.
heroku runs in a production environment by default so it does not install the dev dependencies, you can create a two npm script to avoid this error by running nodemon only in your localhost like that:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"start:dev": "nodemon --watch"
},
and when you want to run the project locally just run in your terminal npm run start:dev and it will load app.js by nodemon.
while in heroku npm start runs by default and load app.js from a normal node command and you get rid of that error.
I just had the same problem. After wasting a lot of time, I discovered that the whole time I was deploying the wrong branch. So if you are writing 'git push heroku master' for instance, 'master' is the branch you are pushing even if you are currently on a different branch.
Looks like nodemon is not in the dependencies, can you provide the package.json, make sure nodemon is in your dependencies
I worked on a simple application and I served it on heroku . I added neutrino to this project. locally with yarn it's working but now I have problem on serving it on heroku. the question is how can i install neutrino on heroku?
here is my package.json
{
"name": "portfolio",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "neutrino start",
"build": "neutrino build"
},
"devDependencies": {
},
"dependencies": {
"neutrino-middleware-sass": "^0.0.1",
"react": "^16.0.0",
"react-burger-menu": "^2.1.10",
"react-dom": "^16.0.0",
"react-hot-loader": "3.0.0-beta.6",
"react-router-dom": "^4.2.2",
"react-typist": "^2.0.4",
"neutrino": "^7.3.1",
"neutrino-preset-react": "^7.3.1"
}
}
and here is the logs on heroku
2017-11-07T20:24:27.718248+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-11-07T20:24:27.718349+00:00 app[web.1]: npm ERR!
2017-11-07T20:24:27.718449+00:00 app[web.1]: npm ERR! Failed at the portfolio#0.1.0 start script 'neutrino start'.
2017-11-07T20:24:27.718537+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-11-07T20:24:27.718625+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the portfolio package,
2017-11-07T20:24:27.718869+00:00 app[web.1]: npm ERR! not with npm itself.
2017-11-07T20:24:27.718943+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-11-07T20:24:27.719014+00:00 app[web.1]: npm ERR! neutrino start
2017-11-07T20:24:27.719102+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-11-07T20:24:27.719214+00:00 app[web.1]: npm ERR! npm bugs portfolio
2017-11-07T20:24:27.719288+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-11-07T20:24:27.719372+00:00 app[web.1]: npm ERR! npm owner ls portfolio
2017-11-07T20:24:27.719460+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-11-07T20:24:27.722711+00:00 app[web.1]:
2017-11-07T20:24:27.722863+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-11-07T20:24:27.722931+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-11-07T20:24:27.785333+00:00 heroku[web.1]: Process exited with status 1
2017-11-07T20:24:27.797858+00:00 heroku[web.1]: State changed from starting to crashed
2017-11-07T20:24:27.800281+00:00 heroku[web.1]: State changed from crashed to starting
2017-11-07T20:24:36.861424+00:00 heroku[web.1]: Starting process with command `npm start`
2017-11-07T20:24:39.981092+00:00 app[web.1]:
2017-11-07T20:24:39.981104+00:00 app[web.1]: > portfolio#0.1.0 start /app
2017-11-07T20:24:39.981106+00:00 app[web.1]:
2017-11-07T20:24:39.981105+00:00 app[web.1]: > neutrino start
2017-11-07T20:24:39.994350+00:00 app[web.1]:
2017-11-07T20:24:39.987770+00:00 app[web.1]: sh: 1: neutrino: not found
2017-11-07T20:24:40.005120+00:00 app[web.1]: npm ERR! Linux 3.13.0-133-generic
2017-11-07T20:24:40.005428+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-11-07T20:24:40.005665+00:00 app[web.1]: npm ERR! node v6.12.0
First up, if you are deploying a static web app or single page app to Heroku, you'll want to make sure your Heroku application is using the nodejs and static buildpacks. You can check which buildpacks you are using with:
heroku buildpacks
Which outputs something like:
❯ heroku buildpacks
=== your-app Buildpack URLs
1. heroku/nodejs
2. https://github.com/hone/heroku-buildpack-static
If you don't have these buildpacks set, you can do it with:
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add https://github.com/hone/heroku-buildpack-static
To configure the static site, drop a static.json file in the root of your project according to the documentation at https://github.com/heroku/heroku-buildpack-static. For starters, if you are building a single page app with HTML5 routing (e.g., react-router), you could start with:
{
"root": "build",
"clean_urls": true,
"routes": {
"/**": "index.html"
}
}
Next up, you can store your development/build dependencies in devDependencies, and set the Heroku config to install them when it is building:
heroku config:set NPM_CONFIG_PRODUCTION=false
When Heroku deploys a Node.js application (which Neutrino is), it tries to use the "start" script defined in package.json to start your app. This won't work for a statically built web app, since we actually want to just build the files and let the static buildpack serve it. To override what Heroku does, you can add a heroku-postbuild script to your package.json:
"scripts": {
"heroku-postbuild": "neutrino build"
}
That should get you going! Lastly, if you are injecting environment variables into your Neutrino app from Heroku, you'll want to make sure you re-build the app, as Heroku doesn't do this by default. This probably entails pushing an empty commit to your repo, or some other re-building mechanism.
I'm using babel-node for ES6 syntax on Heroku, but I get a build error when I deploy. It says "babel-node: not found". I've tried a clean install on my local computer and it works perfectly. Package.json:
{
"name": "secret",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "./node_modules/.bin/babel-node ./bin/www"
},
"engines": {
"node": "7.5.0",
"npm": "5.0.3"
},
"dependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
...
}
}
I appreciate your help! :)
2017-07-17T11:02:26.997876+00:00 heroku[web.1]: State changed from crashed to starting
2017-07-17T11:02:31.839278+00:00 heroku[web.1]: Starting process with command `npm start`
2017-07-17T11:02:38.074157+00:00 heroku[web.1]: State changed from starting to crashed
2017-07-17T11:02:38.062607+00:00 heroku[web.1]: Process exited with status 1
2017-07-17T11:02:37.865774+00:00 app[web.1]:
2017-07-17T11:02:37.865786+00:00 app[web.1]: > secret#0.0.0 start /app
2017-07-17T11:02:37.865787+00:00 app[web.1]: > babel-node ./bin/www
2017-07-17T11:02:37.865787+00:00 app[web.1]:
2017-07-17T11:02:37.936361+00:00 app[web.1]: sh: 1: babel-node: not found
2017-07-17T11:02:37.966452+00:00 app[web.1]: npm ERR! file sh
2017-07-17T11:02:37.966683+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-07-17T11:02:37.966931+00:00 app[web.1]: npm ERR! errno ENOENT
2017-07-17T11:02:37.967106+00:00 app[web.1]: npm ERR! syscall spawn
2017-07-17T11:02:37.967287+00:00 app[web.1]: npm ERR! secret#0.0.0 start: `babel-node ./bin/www`
2017-07-17T11:02:37.967430+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-07-17T11:02:37.967588+00:00 app[web.1]: npm ERR!
2017-07-17T11:02:37.967733+00:00 app[web.1]: npm ERR! Failed at the secret#0.0.0 start script.
2017-07-17T11:02:37.967873+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-07-17T11:02:37.969151+00:00 app[web.1]:
2017-07-17T11:02:37.969374+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-07-17T11:02:37.969484+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-07-17T11_02_37_957Z-debug.log
2017-07-17T11:25:52.044791+00:00 heroku[web.1]: State changed from crashed to starting
2017-07-17T11:25:54.841341+00:00 heroku[web.1]: Starting process with command `npm start`
2017-07-17T11:25:57.407691+00:00 heroku[web.1]: Process exited with status 1
2017-07-17T11:25:57.413873+00:00 heroku[web.1]: State changed from starting to crashed
2017-07-17T11:25:57.310176+00:00 app[web.1]:
2017-07-17T11:25:57.310190+00:00 app[web.1]: > secret#0.0.0 start /app
2017-07-17T11:25:57.310191+00:00 app[web.1]: > babel-node ./bin/www
2017-07-17T11:25:57.310192+00:00 app[web.1]:
2017-07-17T11:25:57.316940+00:00 app[web.1]: sh: 1: babel-node: not found
2017-07-17T11:25:57.335019+00:00 app[web.1]: npm ERR! file sh
2017-07-17T11:25:57.335287+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-07-17T11:25:57.335517+00:00 app[web.1]: npm ERR! errno ENOENT
2017-07-17T11:25:57.335735+00:00 app[web.1]: npm ERR! syscall spawn
2017-07-17T11:25:57.335933+00:00 app[web.1]: npm ERR! secret#0.0.0 start: `babel-node ./bin/www`
2017-07-17T11:25:57.336095+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-07-17T11:25:57.336280+00:00 app[web.1]: npm ERR!
2017-07-17T11:25:57.336449+00:00 app[web.1]: npm ERR! Failed at the secret#0.0.0 start script.
2017-07-17T11:25:57.336614+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-07-17T11:25:57.337985+00:00 app[web.1]:
2017-07-17T11:25:57.338232+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-07-17T11:25:57.338379+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-07-17T11_25_57_323Z-debug.log
babel-node is "not meant for production use". There is a more relevant guide here for using #babel/cli, #babel/core and #babel/preset-env.
The babel dependencies should all be installed as devDependencies and you should transpile your code during in a build script run before Heroku prunes the devDependencies. See this guide
If you move all of your es6 code into a common directory like src at the top level of your app, you can create a build script to transpile everything in that directory to an output directory like build.
"build": "npm run clean && npm run build-babel",
"build-babel": "./node_modules/.bin/babel -d ./build ./src",
"clean": "rm -rf build && mkdir build",
In the example above, the build script will be run automatically by Heroku. clean will create a new build directory, and build-babel will transpile the code and place it in the build directory. After this is completed, Heroku will prune the devDependencies, but you will no longer need Babel.
When Heroku calls start below, it will be running your transpiled code. You should no longer see sh: 1: babel-node: not found.
"scripts": {
"build": "npm run clean && npm run build-babel",
"build-babel": "./node_modules/.bin/babel -d ./build ./src",
"clean": "rm -rf build && mkdir build",
"start": "node ./build/bin/www"
},
One potential gotcha, Do not call build from your start script. If you do, the devDependencies will have been pruned and you will get the following
sh: 1: babel: not found
A little bit late, but here is what I think you are missing:
Step (1): npm install --save babel-cli babel-preset-env in terminal
Note on step 1: Do not save to dev as that will require you to set NPM_CONFIG_PRODUCTION=false
Step (2): You are not compiling anything to babel without adding in the babel boilerplate and or using a babelrc file. Easiest method is to make a .babelrc file in your main app folder, ie. same one your package.json is in and input the following:
{
"presets": ["env"]
}
Note on step 2: With the usage of the env preset you do not need the babel-preset-es2015, etc
Step (3): You can now run your code using babel-node, so in your case execute your start script, ie. ./node_modules/.bin/babel-node ./bin/www
I suggest reading through the NPM module if you need further guidance understanding the preset logic: https://www.npmjs.com/package/babel-preset-env
Furthermore, I would suggest using a process manager like pm2. This allows your node instance to keep alive if it crashes. The forever module used to do this but pm2 is way better. Here is an example of a start script inside your package.json:
"scripts": {
"start": "node ./node_modules/.bin/pm2 start main.json --attach --env production"
}
Procfile (note, I am using nginx but just npm start would work fine):
web: bin/start-nginx npm start
worker: node ./node_modules/.bin/pm2 start worker.json --attach
And here would be your main.json with args to use babel-node (note, keep instance to 1 and do not fork on a web dyno in Heroku):
main.json:
{
"name": "the_awesome",
"script": "app.js",
"instances": 1,
"exec_mode": "cluster"
}
worker.json:
{
"name": "worker",
"script": "/app/lib/worker.js"
}
(4) Add a require('babel-register') hook to your app.js and worker.js if you are using pm2 in cluster mode. If you are using pm2 not in cluster mode, or just not using pm2 then you can use babel-node directly to run your .js or es6 files
Finally, to check if babel-node is really installed you can do the following:
heroku run bash -a {name of your app}
ls ./node_modules/.bin //babel-node should be present
Good luck!