SyntaxError: missing ) after argument list | nodejs | `npm start` - node.js

Running npm start is giving me a syntax error, shown in the output below.
I know how to fix a simple syntax error but I doubt that's the issue here. Looking through various forums didn't result in an answer for me.
[nodemon] starting `npm run lint && node src/app.js`
> server#1.0.0 lint C:\Users\brend\project\server
> node ./node_modules/.bin/eslint **/*.js
C:\Users\brend\project\server\node_modules\.bin\eslint:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\ProgramFiles\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "lint"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! server#1.0.0 lint: `node ./node_modules/.bin/eslint **/*.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#1.0.0 lint script 'node ./node_modules/.bin/eslint **/*.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./node_modules/.bin/eslint **/*.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs server
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls server
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\brend\project\server\npm-debug.log
[nodemon] app crashed - waiting for file changes before starting...
Below is the package.json.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node ./node_modules/nodemon/bin/nodemon.js src/app.js --exec \"npm run lint && node\" ",
"lint": "node ./node_modules/.bin/eslint **/*.js"
},

Ugh.. Okay first thing I ran into was an error saying that '.' is not recognized as an internal or external command. I googled and came to the conclusion that I needed to put node before the script. This resulted in progress; namely that it actually ran the script. Turns out it was needed at the "start" script but not the "lint" script.
My package.json scripts now look like this:
"scripts": {
"start": "node ./node_modules/nodemon/bin/nodemon.js src/app.js --exec \"npm run lint && node\" ",
"lint": "./node_modules/.bin/eslint **/*.js"
},
Which results in:
[nodemon] starting `npm run lint && node src/app.js`
> server#1.0.0 lint C:\Users\brend\project\server
> eslint **/*.js
hello
[nodemon] clean exit - waiting for changes before restart
ps: Thank you for your help kind strangers!

Related

npm ERR! code ELIFECYCLE is being displayed while running "npn start" on window command line for the following package.json file

I am learning full stack web development with Angular and new to web deployment.I am unable to guess the reason behind this npm ERR! code ELIFECYCLE; displayed while running "npn start" on window command line for the following package.json file. I am stuck here and not much help available on google or I am unable to search right answer because of lack of proper keyword required to search the answer.
{
"name": "confusion",
"version": "1.0.0",
"description": "This is a website for Ristorante Con Fusion",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run watch:all",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
},
"author": "Imtiaz",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.3.0",
"node-sass": "^4.13.1",
"onchange": "^3.3.0",
"parallelshell": "^3.0.2"
},
"dependencies": {
"bootstrap": "^4.0.0",
"bootstrap-icons": "^1.0.0-alpha2",
"bootstrap-social": "^5.1.1",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"popper.js": "^1.12.9"
}
}
OutPut:
C:\Users\NEW WS-08\Bootstrap4\conFusion>npm start
> confusion#1.0.0 start C:\Users\NEW WS-08\Bootstrap4\conFusion
> npm run watch:all
> confusion#1.0.0 watch:all C:\Users\NEW WS-08\Bootstrap4\conFusion
> parallelshell "npm run watch:scss" "npm run lite"
child_process.js:422
throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type str
ing. Received type function
←[90m at normalizeSpawnArguments (child_process.js:422:11)←[39m
←[90m at spawn (child_process.js:534:16)←[39m
at C:\Users\NEW WS-08\Bootstrap4\conFusion\node_modules\←[4mparallelshell←[2
4m\index.js:104:17
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\Users\NEW WS-08\Bootstrap4\conFusion\node_modules\
←[4mparallelshell←[24m\index.js:100:6)
←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10
)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m
←[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)←[39
m {
code: ←[32m'ERR_INVALID_ARG_TYPE'←[39m
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 watch:all: `parallelshell "npm run watch:scss" "npm run
lite"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 watch:all script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NEW WS-08\AppData\Roaming\npm-cache\_logs\2020-03-26T08_26
_18_785Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 start: `npm run watch:all`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NEW WS-08\AppData\Roaming\npm-cache\_logs\2020-03-26T08_26
_18_841Z-debug.log
This is a common issue can not be fixed using npm audit fix. All you can do is to copy the actual index.js file of parallelshell into your node_modules directory.
So to do it below are the instructions:
1. Go to https://raw.githubusercontent.com/darkguy2008/parallelshell/master/index.js
2. Copy the content here.
3. Now go to the directory of your project, it may be something like /project/node_modules/parallelshell/index.js
4. Inside the index.js replace the contents with the one you copied from the link in Step 1.
5. Save the file and exit.
Hope this fix will work for you.

nodemon start errors on Heroku

I've been running into the same start error when I deploy onto Heroku. I know it has something to do with my start script but I can't seem to pin down the issue.
I'm running into this error on app start:
2018-10-22T15:31:04.927032+00:00 heroku[web.1]: Process exited with status 1
2018-10-22T15:31:04.944756+00:00 heroku[web.1]: State changed from starting to crashed
2018-10-22T15:31:04.946982+00:00 heroku[web.1]: State changed from crashed to starting
2018-10-22T15:31:04.804183+00:00 app[web.1]:
2018-10-22T15:31:04.804198+00:00 app[web.1]: > Backend# start /app
2018-10-22T15:31:04.804200+00:00 app[web.1]: > nodemon -e js,graphql -x node -r dotenv/config src/index.js
2018-10-22T15:31:04.804202+00:00 app[web.1]:
2018-10-22T15:31:04.810881+00:00 app[web.1]: sh: 1: nodemon: not found
2018-10-22T15:31:04.817652+00:00 app[web.1]: npm ERR! file sh
2018-10-22T15:31:04.818091+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-22T15:31:04.818534+00:00 app[web.1]: npm ERR! errno ENOENT
2018-10-22T15:31:04.818822+00:00 app[web.1]: npm ERR! syscall spawn
2018-10-22T15:31:04.820778+00:00 app[web.1]: npm ERR! Backend# start: `nodemon -e js,graphql -x node -r dotenv/config src/index.js`
2018-10-22T15:31:04.821033+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-10-22T15:31:04.821320+00:00 app[web.1]: npm ERR!
2018-10-22T15:31:04.821464+00:00 app[web.1]: npm ERR! Failed at the Backend# start script.
2018-10-22T15:31:04.821628+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-22T15:31:04.829156+00:00 app[web.1]:
2018-10-22T15:31:04.829411+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-10-22T15:31:04.829659+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-10-22T15_31_04_823Z-debug.log
2018-10-22T15:31:09.008630+00:00 heroku[web.1]: Starting process with command `npm start`
2018-10-22T15:31:12.142111+00:00 app[web.1]:
2018-10-22T15:31:12.142136+00:00 app[web.1]: > Backend# start /app
2018-10-22T15:31:12.142138+00:00 app[web.1]: > nodemon -e js,graphql -x node -r dotenv/config src/index.js
2018-10-22T15:31:12.142140+00:00 app[web.1]:
2018-10-22T15:31:12.151638+00:00 app[web.1]: sh: 1: nodemon: not found
2018-10-22T15:31:12.157445+00:00 app[web.1]: npm ERR! file sh
2018-10-22T15:31:12.157635+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-22T15:31:12.157787+00:00 app[web.1]: npm ERR! errno ENOENT
2018-10-22T15:31:12.157931+00:00 app[web.1]: npm ERR! syscall spawn
2018-10-22T15:31:12.159057+00:00 app[web.1]: npm ERR! Backend# start: `nodemon -e js,graphql -x node -r dotenv/config src/index.js`
2018-10-22T15:31:12.159155+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-10-22T15:31:12.159323+00:00 app[web.1]: npm ERR!
2018-10-22T15:31:12.159423+00:00 app[web.1]: npm ERR! Failed at the Backend# start script.
2018-10-22T15:31:12.159520+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-22T15:31:12.164017+00:00 app[web.1]:
So it can't find nodemon, despite it being installed. Here's my package.json:
{
"name": "Backend",
"scripts": {
"start": "nodemon -e js,graphql -x node -r dotenv/config src/index.js",
"debug": "nodemon -e js,graphql -x node --inspect -r dotenv/config src/index.js",
"playground": "graphql playground",
"dev": "npm-run-all --parallel start playground"
},
"dependencies": {
"bcryptjs": "2.4.3",
"googleapis": "^27.0.0",
"graphql-yoga": "1.12.0",
"jsonwebtoken": "8.2.1",
"multer": "^1.4.0",
"node-schedule": "^1.3.0",
"nodemailer": "^4.6.4",
"prisma-binding": "1.5.17",
"winston": "^2.4.2",
"nodemon": "1.17.3"
},
"devDependencies": {
"dotenv": "5.0.1",
"graphql-cli": "2.15.9",
"nodemon": "1.17.3",
"npm-run-all": "4.1.2",
"prisma": "^1.6.3"
}
}
and my procfile is web: node src/index.js
Any help would be much appreciated, thanks.
It looks like nodemon -e js,graphql -x node -r dotenv/config src/index.js is being called by something other than npm, which is causing the issue with nodemon being missing, regardless of whether or not nodemon is actually present.
Here are some things you can do to isolate the root cause of the issue:
Confirm that the app works locally, with and without nodemon.
Ensure that your Procfile starts with a capitalized P (https://devcenter.heroku.com/articles/procfile#procfile-format)
Update the web directive in your profile to npm start
If the above changes don't work, run through the following:
Navigate to the root directory of your project, and start a remote session as follows: heroku ps:exec.
Once inside your app's dyno, run npm ls. If this fails, your dependencies haven't been installed properly (which looks like a Heroku issue)
If the above command succeeds, run npm start to confirm that the app can launch.

any solution for the following error that appeared after installing onchange and parallelshell node_modules?

after installing the onchange and parallelshell packages for node.js by typing the following command in the node terminal
npm install --save-dev onchange#3.3.0 parallelshell#3.0.2
and configure the package.json file as follow to be able to use the two scripts
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" --npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
}
and when typing 'npm start' to run, i face the following error and cannot solve it. so help me if u can please!
The Error :
confusion#1.0.0 start D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion
npm run watch:all
confusion#1.0.0 watch:all D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion
parallelshell "npm run watch:scss" "npm run lite"
child_process.js:420
throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type string. Received type function
at normalizeSpawnArguments (child_process.js:420:11)
at spawn (child_process.js:522:38)
at D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion\node_modules\parallelshell\index.js:104:17
at Array.forEach ()
at Object. (D:\programming materials\coursera courses\web and mobile dev specialization\course 1\module 1\bootstrap exercise\assignment 1\Bootstrap4\conFusion\node_modules\parallelshell\index.js:100:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 watch:all: parallelshell "npm run watch:scss" "npm run lite"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 watch:all 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! C:\Users\MISR COMP\AppData\Roaming\npm-cache_logs\2018-07-30T15_48_55_679Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 start: npm run watch:all
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 start 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! C:\Users\MISR COMP\AppData\Roaming\npm-cache_logs\2018-07-30T15_48_55_778Z-debug.log
I have had the same problem as you. We are probably doing the same course. Apparently, is a problem with version 3.0.2 of parallelshell. You just have to downgrade to version 3.0.1 and you will not have any more problems:
npm install --save-dev parallelshell#3.0.1
Downgrade the version of parallelshell to 3.0.1 by typing
npm install --save-dev parallelshell#3.0.1
Then type
npm start
And it works!!
Apparently we are doing the same course. So follow the below-mentioned way--
To install two NPM packages onchange and parallelshell use the downgraded version of parallel shell instead of 3.0.2 us 3.0.1:
npm install --save-dev onchange#3.3.0 parallelshell#3.0.1
give space between -- and npm
"watch:scss":"onchange \"css/*.scss\" -- npm run scss"
this will end first error
for parallelshell problem
do this copy content of index.js file from given link
https://raw.githubusercontent.com/darkguy2008/parallelshell/master/index.js
and paste it in your index.file at /project/node_modules/parallelshell/index.js
this will work.
First Un-Install all versions of parallelshell.
npm uninstall --save-dev parallelshell
Second Install parallelshell#3.0.1:
npm install --save-dev parallelshell#3.0.1
Third run start:
npm run start

Issue with npm start command

While setting the environment for the Vue.js app I have encountered the issue with npm start related to node_modules and nodemon.
I am getting this error in the console when running the $npm start command:
$ npm start
> server#1.0.0 start C:\Users\Michał\desktop\it\vueapptrain\server
> node .node_modules/nodemon/.bin/nodemon.js src/app.js --exec 'npm run lint && node'
module.js:515
throw err;
^
Error: Cannot find module 'C:\Users\Michał\desktop\it\vueapptrain\server\.node_modules\nodemon\.bin\nodemon.js'
at Function.Module._resolveFilename (module.js:513:15)
at Function.Module._load (module.js:463:25)
at Function.Module.runMain (module.js:653:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server#1.0.0 start: `node .node_modules/nodemon/.bin/nodemon.js src/app.js --exec 'npm run lint && node'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Any ideas how this can be solved?
Firstly, ensure you have nodemon installed; npm i nodemon -S.
Then, edit the start script in your package.json to this,
node ./node_modules/.bin/nodemon src/app.js --exec 'npm run lint && node'

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