从cmd调用时,Nodejs找不到我的节点模块

时间:2016-06-25 08:50:37

标签: javascript node.js windows

当我在全局安装时从命令行调用我的节点模块时出现错误

could not find /node_modules/insect-tool/cli.js

我检查全局节点模块文件夹,它就在那里。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

它的发生是因为你没有维护pacakge.json属性中的main文件的全局模块结构或问题,你必须放置cli.js而不是index.js

package.json主接受模块的入口点

将您的输入javascript文件放在bin目录

点击此链接获取更多info

  

示例package.json

{
  "author": "Uzaif nilger",
  "license": "BSD",
  "name": "test-module",
  "version": "0.0.1",
  "description": "This is my first module.",
  "bin": {
    "test-module-exec": "bin/test-module.js"
  },
  "main" : "cli.js",
  "preferGlobal": "true"
}

希望它为你工作