简体   繁体   中英

Globally-installed NodeJS npm module does not execute the main/bin JavaScript file with node

I've a package.json like this:

{
  "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.

But generated code doesn't include node.exe or 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).

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.

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 ? Even though the shebang is a *nix specific directive, npm depends on its presence to create the shim for the .cmd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM