Skip to content

Instantly share code, notes, and snippets.

@ardcore
Created June 29, 2011 16:53
Show Gist options
  • Save ardcore/1054298 to your computer and use it in GitHub Desktop.
Save ardcore/1054298 to your computer and use it in GitHub Desktop.
yui3 require?
pilkowski@dev:~$ npm ls | grep yui3
└─┬ [email protected]
└── [email protected]
pilkowski@dev:~$ node -v
v0.4.8
pilkowski@dev:~$ npm -v
1.0.13
pilkowski@dev:~$ node
> var y = require('yui3')
> !!y
true
> y.YUI
Error: YUI3 Core package was not found; npm install yui3-core
at /home/pilkowski/node_modules/yui3/lib/node-yui3.js:299:15
at /home/pilkowski/node_modules/yui3/lib/node-yui3.js:13:15
at Object.YUI (/home/pilkowski/node_modules/yui3/lib/node-yui3.js:24:15)
at [object Context]:1:2
at Interface.<anonymous> (repl.js:171:22)
at Interface.emit (events.js:64:17)
at Interface._onLine (readline.js:153:10)
at Interface._line (readline.js:408:8)
at Interface._ttyWrite (readline.js:585:14)
at ReadStream.<anonymous> (readline.js:73:12)
>
@medikoo
Copy link

medikoo commented Jul 2, 2011

Strange, it works fine on my side.
Which way did you install yui3 ? npm install yui3 ?

Other thing, it's strange that you have 'node_modules' in your home folder. As far as I understand 'node_modules' concept, it should exist per project and within project path. So basically you should create folder for project you're working e.g. /home/pilkowski/project/ and there play with it.
If you end up having 'node_modules' in your home path you may experience unexpected behavior when you'll try to create some other unrelated project within this path.

@ardcore
Copy link
Author

ardcore commented Jul 2, 2011

it may be that yui packages are fixed now. see my conversation with davglass and izs on twitter:
http://twitter.com/#!/davglass/status/86196798414270464
http://twitter.com/#!/davglass/status/86210345521250304

about my modules - yeah, it was just npm install yui3. i think this is how npm install works; if you'd like a module to be included in your project package, you should use npm link command.
node_modules are in my $HOME instead of /usr/local/something because i've installed npm locally (without root access) using --prefix option.

@medikoo
Copy link

medikoo commented Jul 2, 2011

I think you work with node, that was installed with root access (which generally it's discouraged), and because of that you can't install packages globally, so you try to workaround it by installing packages in folder of your choice $HOME/node_modules and linking them into your project (?) I think it's a bit messy approach, and anyway it's workaround for just a piece of functionality that global install offer.

I think real workaround you want is to install node the way it's intended: locally (it will override root node install in your PATH), then you won't be limited and you'll be able to install packages globally.

Both npm link and npm install, install packages for specific project, real difference in my eyes is:
npm link - for including packages that you also work on. This packages doesn't have to be published on npm and your changes are immediately visible in projects that linked them.
npm install - for including packages that are published on npm and you want just to use them(no need to edit) like yui3. Again what's important it's installed for specific project, and not for your whole $PATH (see npm install -g for that). That's why I pointed that node_modules in your $HOME seems strange :)

Both commands install packages in same place (node_modules folder in your project folder).

You may also install package globally (with npm install -g) and then use npm link instead npm install to install it in specific project, but the only difference is that you save some disk space and put dependencies of all projects in one folder (it's NODE_PATH/lib/node_modules/). I actually don't favor this approach that much. Imagine that you switch node versions, and once install packages globally to node v0.4 path and other time to node v0.5 path, it's making a mess.

I work only locally (no global package installs), from my experience global install may be handy only if you want call e.g. jslint from anywhere in your shell. What's good to know is that all packages should work well locally, the warning you see sometimes, that tells you to install it globally, it's just suggestion that probably you want to have it's bin/* in your $PATH and for this you need to install it globally. Installing locally just forces you to address it's bin path directly, no other limitations.

Root install is totally different story, it may only be needed if you want to mess with something that needs root access. I never had need for that.

Anyway no matter how you work with your packages, above code should work, so it's good that it turned out there's some bug that they know about :)

@ardcore
Copy link
Author

ardcore commented Jul 2, 2011

I think the main difference is that we're not talking about my own machine, it's a dev server on which node is used by 5 users now (and 10 more potentially). It simply makes no sense to make them all install node locally.

by 'installing node globally' I meant 'make; sudo make install'. it does not cause node to run with root privileges, it simply copies/links binaries to /usr/local/bin and allows them to be used by anyone on the server. standard way of installing stuff for more than one user.

from what I understand, in my setup it works like this:

  • npm link works as you said,
  • npm install installs module to be used across your projects. notice that module doesn't have to be published on npm - you can as well 'npm install .' if you provide a proper manifest file. other users on the server aren't affected by such installation.

@medikoo
Copy link

medikoo commented Jul 2, 2011

npm install installs package for use in current project. if you do npm install foo in ~/projects/a and then try to use foo package in ~/projects/b you'll get error as it won't be visible.
npm install . all it does is installing dependencies (into ./node_modules) of project you're currently at. Dependencies are read from package.json file. In other words npm install . means - make project I'm at, ready for use.

According to your environment, it's quite understood that you want to share same node binary. I wonder how it should be resolved (?)
I can think now of two ways, one is to override setting for global path for modules (if it's possible, I'm just guessing), so it doesn't try to install globally packages where node lives but somewhere within your user path. Other way would be, is that you all agree with which node version you work and each of you have same version installed locally.

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment