发布并安装globaly后找不到节点npm包throw use strict:命令 [英] Node npm package throw use strict: command not found after publish and install globaly

查看:56
本文介绍了发布并安装globaly后找不到节点npm包throw use strict:命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发布npm软件包,当我在全局安装该软件包并尝试运行cli命令时出现此错误:

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);

package.json bin部分:

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?

推荐答案

您的脚本应以 shebang 行,否则它将作为shell脚本执行(因此会出现错误).

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

将此作为第一行添加到 dist/myPack.js :

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

#!/usr/bin/env node

这篇关于发布并安装globaly后找不到节点npm包throw use strict:命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆