0

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?

1
  • Try: var reltoabs = require('app/reltoabs'); Commented Sep 15, 2013 at 2:04

1 Answer 1

2
+50

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')
Sign up to request clarification or add additional context in comments.

1 Comment

Actually that seemed to fix the problem! Thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.