简体   繁体   中英

Nodejs cannot find my node module when calling from cmd

When I call my node module from the command line when it is installed globally I get an error saying it

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

I check in the global node modules folder and it is there. How do I fix this?

Its happen because of you doesn't maintain the global module structure or problem with your pacakge.json file in main property you have to put cli.js instead of index.js

package.json main accept entry point of your module

Place your entry javascript file in bin directory

follow this link for more info

Sample 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"
}

hope its work for you

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