Domanda

I'm working on creating a node library which includes a CLI to work with it.

The full (however not long) code is found at https://github.com/claydiffrient/reltoabs.

Because I'm actively developing this, I'm using a npm link to work with in during development.

The portion giving me trouble seems to be in the cli.js file. When I include the module via a var reltoabs = require('reltoabs') node spits back an error saying that the reltoabs module doesn't exist, however it is in the node_modules. Any idea how I can make this work?

È stato utile?

Soluzione

If the module you're trying to require isn't a native module and doesn't start with a path identifier, then Node will start by looking in the parent directory of the current module and appends /node_modules. Node will then look in that directory, and if the module isn't there, then it will iterate up the filesystem tree until the root is reached.

Assuming you're developing from a modules folder, your require does these searches:

/module/path/lib/node_modules/reltoabs
/path/lib/node_modules/reltoabs
/lib/node_modules/reltoabs

This doesn't explain the error you're getting, but to avoid errors like yours, references files relatively when possible:

var reltoabs = require('./reltoabs')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top