Yeah, share the actual example code.

require() works fine with absolute paths.

$ cat > b.js
console.log('hello from b', __filename)
^D
$ cat > a.js
require(require('path').resolve('b.js'))
^D
$ node a.js
hello from b /Users/isaacs/dev/js/node-master/b.js


On Wed, Dec 26, 2012 at 4:33 PM, Domenic Denicola
<[email protected]> wrote:
> I don't believe `require` works with absolute paths, like those generated by
> path.resolve. (Could be wrong.) If I'm correct, then you may find
> path.relative to be a useful method.
>
> Also note that of course path.resolve without a second argument will resolve
> relative to process.cwd(), not relative to __filename. This is rarely what
> you want.
>
>
> On Wednesday, December 26, 2012 10:12:13 AM UTC-5, [email protected]
> wrote:
>>
>> Hi,
>>
>> Trying to simply require() in a .js file seems to be failing for me here,
>> raising a MODULE_NOT_FOUND error.
>> However - a fs.readFileSync() on the file does work.
>>
>> My current failing debug code:
>> // Fails
>> require(require('path').resolve(module_file));
>>
>> // Works
>> require('fs').readFileSync(require('path').resolve(module_file), 'UTF8');
>>
>> Since the readFileSync() call works I can rule out any file/directory
>> permissions leaving me with absolutely no ideas left as to why require()
>> cannot find the file?
>>
>> Anyone have any debugging pointers to share?
>>
>> Darren
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to