Deploying TypeScript Express Server to Heroku - node.js

In attempting to deploy an Express TypeScript server to Heroku, I am encountering an error. I ran heroku logs --tail and this is the output:
2021-12-02T21:09:20.152292+00:00 app[web.1]: > backend#1.0.0 start /app
2021-12-02T21:09:20.152292+00:00 app[web.1]: > ts-node src/index.ts
2021-12-02T21:09:20.152292+00:00 app[web.1]:
2021-12-02T21:09:20.164793+00:00 app[web.1]: sh: 1: ts-node: not found
2021-12-02T21:09:20.176470+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-12-02T21:09:20.176764+00:00 app[web.1]: npm ERR! syscall spawn
2021-12-02T21:09:20.176897+00:00 app[web.1]: npm ERR! file sh
2021-12-02T21:09:20.177050+00:00 app[web.1]: npm ERR! errno ENOENT
2021-12-02T21:09:20.184008+00:00 app[web.1]: npm ERR! backend#1.0.0 start: `ts-node src/index.ts`
2021-12-02T21:09:20.184048+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-12-02T21:09:20.184122+00:00 app[web.1]: npm ERR!
2021-12-02T21:09:20.184186+00:00 app[web.1]: npm ERR! Failed at the backend#1.0.0 start script.
2021-12-02T21:09:20.184240+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-12-02T21:09:20.189489+00:00 app[web.1]:
2021-12-02T21:09:20.192700+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-12-02T21:09:20.192779+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-12-02T21_09_20_184Z-debug.log
2021-12-02T21:09:20.372397+00:00 heroku[web.1]: Process exited with status 1
2021-12-02T21:09:20.745674+00:00 heroku[web.1]: State changed from starting to crashed
From my own research, it was suggested I put in a buildpack for TypeScript, the one that comes up on heroku buildpacks:search is zidizei/typescript. I had installed that without success.
Further research suggested heroku node/js buildpack. I ran heroku buildpacks:set heroku/nodejs and tried that without success. So I switch back to zidizei, everything compiles and builds, except for the server start.
I'm confused as to what the root of the problem is, and I think I may have gotten turned around.
Additional steps I've taken:
// package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts",
"dev": "ts-node-dev src/index.ts",
"build": "tsc",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"db:generate-migration": "yarn typeorm -- migrate:generate --config ormconfig.ts --connection --name",
"db:run-migration": "yarn typeorm -- migration:run"
// Procfile
web: npm start
Alternatively, are there any strong heroku contenders for hosting an express server and a Postgres DB?
Adding: I noticed that when I entered into the environment using heroku run bash --app <my_app_name> that the dist folder is being built. Is the solution to point my start script to something like node dist/src/index.js?

Okay, so for anyone else that is reading this.
My solution was:
In package.json all I had to do was change my start script from
"start": "ts-node src/index.ts",
to
"start": "node dist/src/index.js",
Seems that at some point I got turned around in my documentation and was looking every which way except the obvious one.

Related

How to solve the Error in deploying react app on Heroku

I run yarn install and yarn start locally for my project and it works fine. However, as soon as I push it to Heroku, I am unable to deploy it with the following error log:
2021-05-10T16:40:06.622555+00:00 app[web.1]: > react-scripts start
2021-05-10T16:40:06.622556+00:00 app[web.1]:
2021-05-10T16:40:06.627252+00:00 app[web.1]: sh: 1: react-scripts: not found
2021-05-10T16:40:06.636894+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-05-10T16:40:06.637303+00:00 app[web.1]: npm ERR! syscall spawn
2021-05-10T16:40:06.637496+00:00 app[web.1]: npm ERR! file sh
2021-05-10T16:40:06.637766+00:00 app[web.1]: npm ERR! errno ENOENT
2021-05-10T16:40:06.644457+00:00 app[web.1]: npm ERR! bleh#0.1.0 start: `react-scripts start`
2021-05-10T16:40:06.644627+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-05-10T16:40:06.644771+00:00 app[web.1]: npm ERR!
2021-05-10T16:40:06.644922+00:00 app[web.1]: npm ERR! Failed at the bleh#0.1.0 start script.
2021-05-10T16:40:06.645043+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-05-10T16:40:06.654910+00:00 app[web.1]:
2021-05-10T16:40:06.655128+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-05-10T16:40:06.655306+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-05-10T16_40_06_646Z-debug.log
2021-05-10T16:40:06.706089+00:00 heroku[web.1]: Process exited with status 1
2021-05-10T16:40:06.778374+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-10T16:41:26.103511+00:00 app[api]: Deploy 1f4ec645 by user holliu9999#gmail.com
2021-05-10T16:41:26.103511+00:00 app[api]: Release v7 created by user holliu9999#gmail.com
2021-05-10T16:41:26.390448+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-10T16:41:30.000000+00:00 app[api]: Build succeeded
2021-05-10T16:41:32.398941+00:00 heroku[web.1]: Starting process with command `npm start`
In addition, I do only contain the yarn.lock in my directory so I am confused why it still runing npm. And here is my package.json file:
{
"name": "bleh",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.9.0"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-fontawesome": "^1.6.1",
"react-infinite": "^0.11.2",
"react-infinite-loader": "^1.0.2",
"react-router": "^3.0.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
You need to have a back-end server like node with express and config the script npm start. Go to Package.json --> scripts --> and add the script --> "start": "node app or index" depend of your root file. Btw you need to put the react application on the public folder of your backend.
Heroku needs a backend to start correctly.
You can see the express setup https://www.npmjs.com/package/express or http://expressjs.com/en/starter/hello-world.html

Heroku npm start starts from different location

I have a fully functional NodeJs application with a submodule bundled inside it, so the submodule is the main application, and the other node project is built upon it.
I would like to run the submodule (the inner application) from the outer application. It might sound strange, but this is really what I would like to achieve.
It works fine when I run it in a local environment, but I can not make it work on Heroku.
Locally I run it with the command: heroku local web
My Procfile: web: npm run startwithouteslint
My outer package.json:
{
"name": "chatgine-pension",
"version": "1.0.0",
"description": "Chatgine-pension application",
"engines": {
"node": "10.x"
},
"main": "chatiety-engine/index.js",
"scripts": {
"startwithouteslint": "npm run startwithouteslint --prefix chatiety-engine",
"start": "eslint \"**/*.js\" && npm start --prefix chatiety-engine",
"test": "eslint \"**/*.js\" && mocha test --recursive --exit",
"coverage": "eslint \"**/*.js\" && nyc --reporter=text mocha test --recursive --exit"
},
"dependencies": {},
"devDependencies": {},
"repository": {},
"keywords": [],
"license": "custom"
}
My inner package.json (inside chatiety-engine folder):
{
"name": "chatiety-engine",
"version": "1.0.0",
"description": "Chatiety-engine application",
"engines": {
"node": "10.x"
},
"main": "index.js",
"scripts": {
"startwithouteslint": "node index.js",
"start": "eslint \"**/*.js\" && node index.js",
"test": "eslint \"**/*.js\" && mocha test --recursive --exit",
"coverage": "eslint \"**/*.js\" && nyc --reporter=text mocha test --recursive --exit"
},
"dependencies": {},
"devDependencies": {},
"repository": {},
"keywords": [],
"license": "custom"
}
Structure of the project:
The error message from Heroku:
2019-11-25T16:43:45.727225+00:00 heroku[web.1]: Starting process with command `npm run startwithouteslint`
2019-11-25T16:43:48.223968+00:00 app[web.1]:
2019-11-25T16:43:48.223991+00:00 app[web.1]: > chatgine-pension#1.0.0 startwithouteslint /app
2019-11-25T16:43:48.223993+00:00 app[web.1]: > npm run startwithouteslint --prefix chatiety-engine
2019-11-25T16:43:48.223995+00:00 app[web.1]:
2019-11-25T16:43:48.559728+00:00 app[web.1]: npm ERR! code ENOENT
2019-11-25T16:43:48.560276+00:00 app[web.1]: npm ERR! syscall open
2019-11-25T16:43:48.560632+00:00 app[web.1]: npm ERR! path /app/chatiety-engine/package.json
2019-11-25T16:43:48.563785+00:00 app[web.1]: npm ERR! errno -2
2019-11-25T16:43:48.563789+00:00 app[web.1]: npm ERR! enoent ENOENT: no such file or directory, open '/app/chatiety-engine/package.json'
2019-11-25T16:43:48.563792+00:00 app[web.1]: npm ERR! enoent This is related to npm not being able to find a file.
2019-11-25T16:43:48.563793+00:00 app[web.1]: npm ERR! enoent
2019-11-25T16:43:48.570839+00:00 app[web.1]:
2019-11-25T16:43:48.571073+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-25T16:43:48.571158+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-25T16_43_48_563Z-debug.log
2019-11-25T16:43:48.578800+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-25T16:43:48.579173+00:00 app[web.1]: npm ERR! errno 254
2019-11-25T16:43:48.580465+00:00 app[web.1]: npm ERR! chatgine-pension#1.0.0 startwithouteslint: `npm run startwithouteslint --prefix chatiety-engine`
2019-11-25T16:43:48.580626+00:00 app[web.1]: npm ERR! Exit status 254
2019-11-25T16:43:48.580875+00:00 app[web.1]: npm ERR!
2019-11-25T16:43:48.581043+00:00 app[web.1]: npm ERR! Failed at the chatgine-pension#1.0.0 startwithouteslint script.
2019-11-25T16:43:48.581209+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-25T16:43:48.587148+00:00 app[web.1]:
2019-11-25T16:43:48.587357+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-25T16:43:48.587493+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-25T16_43_48_581Z-debug.log
2019-11-25T16:43:48.666923+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-25T16:43:48.642599+00:00 heroku[web.1]: Process exited with status 254
It seems like Heroku appends the /app at the beginning of the path but I have no idea why, and where could I turn it off.
EDIT: I was able to list all the environment variables used by Heroku, and two of those are very likely to cause the problem:
PWD=/app
HOME=/app
So far so good, but I can not override these env. variables. Do you have any idea how could I achieve this?
Thanks for any help in advance!
I was having the same problem. Just realize that my code was crashing. You have to fix the bug on your code, then this message "npm run startwithouteslint" will disappear. You can run "npm run start" in your terminal and some clues of your errors it will be on the screen.

Heroku failing node app - try to run nodemon instead of node

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

heroku failed at the build script but heroku local web is fine

I followed instructions, pushed repo to heroku and I find it crashed.
I use heroku/nodejs as a buildpack.
Procfile:
web: npm run build && npm run heroku-server
Scripts:
"scripts": {
"heroku-server": "cross-env SERVER_PROD_PORT=$PORT SERVER_PROD_HOST=0.0.0.0 npm run server",
"browser": "cross-env NODE_ENV=development WEBPACK_CONFIG=browser_dev webpack-dev-server --open",
"build": "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
"build-analyze": "cross-env BUNDLE_ANALYZER=1 NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
"build-browser": "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod webpack --colors",
"build-run": "npm run build && npm run server",
"build-static": "cross-env NODE_ENV=production WEBPACK_CONFIG=static webpack --colors",
"build-static-run": "npm run build-static && npm run static",
"clean": "rimraf dist",
"lint": "eslint .",
"server": "node dist/server",
When I run scripts from Procfile or $ heroku local web everything is builing fine. But pushed repo is throwing the errors in logs:
2018-01-30T22:23:05.780537+00:00 heroku[web.1]: Starting process with command `npm run build && npm run heroku-server`
2018-01-30T22:23:07.502982+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-30T22:23:07.491558+00:00 heroku[web.1]: Process exited with status 1
2018-01-30T22:23:07.292672+00:00 app[web.1]:
2018-01-30T22:23:07.292693+00:00 app[web.1]: > beers#2.10.0 build /app
2018-01-30T22:23:07.292694+00:00 app[web.1]: > cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors
2018-01-30T22:23:07.292695+00:00 app[web.1]:
2018-01-30T22:23:07.421065+00:00 app[web.1]: events.js:137
2018-01-30T22:23:07.421068+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-01-30T22:23:07.421070+00:00 app[web.1]: ^
2018-01-30T22:23:07.421071+00:00 app[web.1]:
2018-01-30T22:23:07.421073+00:00 app[web.1]: Error: spawn webpack ENOENT
2018-01-30T22:23:07.421074+00:00 app[web.1]: at _errnoException (util.js:1003:13)
2018-01-30T22:23:07.421076+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:201:19)
2018-01-30T22:23:07.421078+00:00 app[web.1]: at onErrorNT (internal/child_process.js:389:16)
2018-01-30T22:23:07.421080+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:152:19)
2018-01-30T22:23:07.421081+00:00 app[web.1]: at Function.Module.runMain (module.js:703:11)
2018-01-30T22:23:07.421083+00:00 app[web.1]: at startup (bootstrap_node.js:193:16)
2018-01-30T22:23:07.421085+00:00 app[web.1]: at bootstrap_node.js:617:3
2018-01-30T22:23:07.426513+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-01-30T22:23:07.426855+00:00 app[web.1]: npm ERR! errno 1
2018-01-30T22:23:07.428042+00:00 app[web.1]: npm ERR! beers#2.10.0 build: `cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors`
What am I missing?
First of all, don't put your "npm run build" step in your Procfile.
Doing so will cause that step to run every time your web dyno restarts, which is not what you want.
Instead, you want to run webpack (or whatever else you need for making sure the dependencies you need are present in your app) during slug compilation.
By virtue of the fact that you are using the heroku/node.js buildpack, it will automatically take care of running "npm install" for you (or yarn install, if you choose to use the yarn package manager instead).
However, if you need more than npm/yarn install (e.g. if you need to run webpack to bundle client dependencies), then you need to provide the slug compiler with additional instructions for those steps. A good way to do that is by using heroku-specific build steps.
So, for example, you might want to run webpack in a heroku-postbuild step in your package.json "scripts", e.g.:
"heroku-postbuid" : "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
However, in addition you need to be aware that by default Heroku won't install any of your package.json devDependencies. So if you have webpack itself listed in devDependencies, you won't be able to use it in a heroku-postbuild step by default.
The way to workaround that is to either move webpack (together with any other build dependencies you need) to "dependencies" (instead of "devDependencies"), or to set config var NPM_CONFIG_PRODUCTION to false:
heroku config:set NPM_CONFIG_PRODUCTION=false
For more info, see here and here.

babel-node is not getting installed on Heroku

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!

Resources