Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node npm package throw use strict: command not found after publish and install globaly

I am trying to publish npm package, when i am install the package globally and try to run the cli command i get this errors:

/.nvm/versions/node/v0.12.2/bin/myPack: line 1: use strict: command not found /.nvm/versions/node/v0.12.2/bin/myPack: line 3: syntax error near unexpected token `(' /.nvm/versions/node/v0.12.2/bin/myPack: line 3: `var _commandLineArgs = require('command-line-args');' 

The top of the file that the error refer to:

'use strict';  var _commandLineArgs = require('command-line-args');  var _commandLineArgs2 = _interopRequireDefault(_commandLineArgs); 

The package.json bin section:

  "bin": {     "myPack": "dist/myPack.js"   } 

When i am running this in my local development this works well, what is the problem?

like image 931
user233232 Avatar asked Dec 18 '15 10:12

user233232


1 Answers

Your script should start with a shebang line, otherwise it will be executed as a shell script (hence the errors).

Add this as first line to dist/myPack.js:

#!/usr/bin/env node 
like image 175
robertklep Avatar answered Sep 20 '22 13:09

robertklep