1

I wrote a NodeJs script using ES6 features (default parameters and destructuring), so I put the following shebang:

#!/bin/node --harmony_destructuring --harmony_default_parameters

But then node tells me:

/bin/node: bad option: --harmony_destructuring --harmony_default_parameters

Both of these options are listed in node --v8-options | grep "in progress" so they should be both valid, but maybe my syntax is incorrect. I tried different syntaxs:

/bin/node: bad option: --harmony_destructuring=true --harmony_default_parameters=true
/bin/node: bad option: --harmony_destructuring true --harmony_default_parameters true

With no luck.

jolivier
  • 7,380
  • 3
  • 29
  • 47
  • Did your question get answered? I believe this is solved in Node v14+ or possibly earlier. This works for me: `#!/usr/bin/env node --harmony-promise-any --harmony-string-replaceall` – chharvey Mar 29 '21 at 16:46
  • I couldn't find easily a related PR or issue in `node` but it may have been fixed in the last 5 years if it works on your binary. I haven't tried since then. – jolivier Mar 31 '21 at 08:28

1 Answers1

1

Although I found this fascinating answer for python, I don't have something that clever for javascript available. I think you are going to need 2 separate files: 1 small wrapper script to force the arguments you need to node and a separate file for your javascript.

#!/bin/sh
exec node --harmony_destructuring=true --harmony_default_parameters=true my-script.js "$@"
Community
  • 1
  • 1
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • Ok that's what I was assuming, shebang has a different parameter handling. Unforunately even with env it doesn't work: `/usr/bin/env: node --harmony_destructuring --harmony_default_parameters: No such file or directory` whereas the same command in my shell works – jolivier Dec 10 '15 at 15:01
  • That means your PATH does not include `/bin`, which is very unusual. Try `#!/usr/bin/env /bin/node --harmony_destructuring --harmony_default_parameters` – Peter Lyons Dec 10 '15 at 17:25
  • Indeed my PATH doesn't contain `/bin` (I have archlinux, binaries are in /usr/bin). But your suggestion doesn't work either, I guess env doesnt solve the argument parsing issue and it tries to execute the file `node option1 option2` wich doesnt exist. – jolivier Dec 10 '15 at 19:49