8

The same could be achieved in node.js using --harmony flag like this:

node --harmony app.js

So it will be add support for EcmaScript6.

How to run gulp commands with harmony flag?

FelikZ
  • 2,976
  • 4
  • 32
  • 41
  • possible duplicate of [Why "gulp-jest" is failing with: "Please run node with the --harmony flag!"?](http://stackoverflow.com/questions/28315796/why-gulp-jest-is-failing-with-please-run-node-with-the-harmony-flag) – msanford Apr 16 '15 at 13:52
  • Usually one can achieve something like that by `gulp [options for gulp] -- --harmony`, where everything after `--` should be passed to Node.js . – Robert Rossmann Apr 16 '15 at 13:55

3 Answers3

8

A simpler solution would be to use harmonize : https://github.com/dcodeIO/node-harmonize

Just install harmonize and then require like so: require("harmonize")();

jrader
  • 670
  • 1
  • 5
  • 15
5

You can do that in the following way:

alias gulp='node --harmony `which gulp`'

Place this in ~/.bashrc file and gulp will always run in harmony mode.

If you are a docker user and want to use gulp with harmony inside a container, you can do that in the following way:

docker run -ti \
    --name container \
    nodejs-image-with-gulp-pre-installed \
    bash -ci 'gulp task'

The key is to use -i flag with a bash, so your alias will be loaded successfully. Otherwise it will run gulp itself without harmony support.

FelikZ
  • 2,976
  • 4
  • 32
  • 41
  • You can't just name the alias the same way, the command you try to resolve (`which gulp`) is named. This should end up in an error, since `which gulp` will resolve to ``gulp: aliased to node --harmony `which gulp` `` – naeramarth7 Apr 16 '15 at 16:08
  • 1
    @naeramarth7 thanks for the reply. Yeah I also was thought about that but actualy `which gulp` even after an alias, returns the actual path to a gulp binary. You can check it by your own, it is just works. – FelikZ Apr 17 '15 at 08:41
  • checked that beforehand - does not work in `zsh` on `OS X 10.10` (besides the missing quote on the alias line). Gives me `Error: Cannot find module '/gulp'` since it tries to run exactly this command: ``node --harmony gulp: aliased to node --harmony `which gulp` ``. – naeramarth7 Apr 17 '15 at 08:47
  • It worked for me with no problems - both for `gulp any-task` commands and vanilla `gulp`. I ran it in GNOME terminal 3.6.2, on 64-bit Linux Mint 17.1. – Andrew Faulkner Aug 28 '15 at 08:18
3

To follow up on FelikZ's solution:

npm run

You can update your package.json and add your gulp commands to the section scripts:

{
  "scripts": {
    "start": "node --harmony `which gulp` start",
    "build": "node --harmony `which gulp` build",
    ...
  }
}

These commands can then be called with npm run start, npm run build etc.

If you want to call all your gulp commands through npm (without defining them separately) you can do as follows:

{
  "scripts": {
    "gulp": "node --harmony `which gulp`"
  }
}

To run gulp start, you would call npm run -- start etc.

Alternative: io.js

If you want to use --harmony by default, you could also have a look at io.js:

https://iojs.org/en/es6.html

nils
  • 25,734
  • 5
  • 70
  • 79