[英]Globally-installed NodeJS npm module does not execute the main/bin JavaScript file with node
I've a package.json
like this: 我有这样的
package.json
:
{
"name": "some-module",
"version": "1.0.0",
"bin": "./bin/some-module.js",
"main": "./bin/some-module.js",
"description": "Some module description",
"homepage": "http://my.home.page.com",
"author": {
"name": "Matias Fidemraizer",
"email": "no-email@no-email.com",
"url": "http://some.url.com"
},
"engines": {
"node": ">=0.4.0"
},
"keywords": [
"somekeyword"
],
"license": {
"type": "Apache v2",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"preferGlobal": true,
"repository": {
"type": "git",
"url": "git://github.com/some/repo"
},
"dependencies": {
"somedependency": "*"
}
}
When I try to install the whole module typing npm -g install /path/to/module/folder
, npm creates a .cmd
file on AppData folder in the default node_modules
location for global installations as expected. 当我尝试安装整个模块键入
npm -g install /path/to/module/folder
, npm会在默认node_modules
位置的AppData文件夹上创建一个.cmd
文件,以便按预期进行全局安装。
But generated code doesn't include node.exe
or node
: 但生成的代码不包含
node.exe
或node
:
"%~dp0\node_modules\some-module\bin\some-module.js" %*
... so when I try to execute my some-module
module in CMD, PowerShell or whatever, it's executed using Windows Script Host (WSH). ...所以当我尝试在CMD,PowerShell或其他任何地方执行我的
some-module
模块时,它是使用Windows脚本宿主(WSH)执行的。
For that reason I thought comparing package.json
of some existing module like YUIDocJS would be enough to find out what's causing this problem but I can't figure out what's wrong in my own package.json
so it doesn't create the expected global installation. 出于这个原因,我认为比较一些像YUIDocJS这样的现有模块的
package.json
就足以找出造成这个问题的原因但是我无法弄清楚我自己的package.json
什么问题所以它不能创建预期的全局安装。
Thank you in advance for your effort. 提前感谢您的努力。
Do you have the shebang #!/usr/bin/env node
at the top of the file referenced in the bin
property of your package.json
? 你是否在
package.json
的bin
属性中引用的文件顶部有shebang #!/usr/bin/env node
? Even though the shebang is a *nix specific directive, npm
depends on its presence to create the shim for the .cmd
即使shebang是* nix特定指令,
npm
依赖于它的存在来为.cmd
创建垫片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.