Bug 1006531 - node can't find requires without NODE_PATH
Summary: node can't find requires without NODE_PATH
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: nodejs
Version: 19
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: T.C. Hollingsworth
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-09-10 18:51 UTC by Fabian Deutsch
Modified: 2013-09-11 07:34 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-09-10 23:01:41 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Fabian Deutsch 2013-09-10 18:51:17 UTC
Description of problem:
I need to call
NODE_PATH=/usr/lib/node_modules node file.js
otherwise (without NODE_PATH) node won't find the required modules.

Comment 1 T.C. Hollingsworth 2013-09-10 23:01:41 UTC
This is by design.

Node.js' global module search path is by default set only to './node_modules', to allow the developer to create separate directories with separate dependency chains, similar to how virtualenv works with Python.  To use yum-installed dependencies, just `npm link` them into your local project.  To use dependencies we don't have yet, just `npm install` them.

For instance:

% mkdir test

% cd test

% cat >test.js <<EOF
> var request = require('request')
> request('https://badges.fedoraproject.org/user/fabiand/json', function (error, response, body) {
>  if (!error && response.statusCode == 200) {
>    var num = JSON.parse(body).assertions.length
>    console.log('You have ' + num + ' badges!')
>  }
> })
> EOF

% node test.js
Error: Cannot find module 'request'

% npm link request

% node test.js
You have 20 badges!

For more information on the rationale behind this, see the npm FAQ:
https://npmjs.org/doc/faq.html#I-installed-something-globally-but-I-can-t-require-it

Comment 2 Fabian Deutsch 2013-09-11 07:34:46 UTC
Thanks for this explanation.


Note You need to log in before you can comment on or make changes to this bug.