문제

I'm trying to get the functionality of CoffeeScript.compile in node.js.

I've installed node on Cygwin in Windows, and installed coffee script with npm.

I can use the coffee command fine but if I try to

require("coffee-script");

I get "Cannot find module 'coffee-script'" in node.

Am I going about this the wrong way?

도움이 되었습니까?

해결책

It sounds like require isn't looking in npm's global install path. Run

require.paths

from the Node REPL to see which paths are being looked in. On the command line, run

npm ls -g

to see the directory that npm is installing global libraries in (it's /usr/local/lib on my Mac). Add /node_modules to that, and add it to require.paths. You can do this on a one-time basis by running

require.paths.shift('/usr/local/lib/node_modules');

(Update: Modifying require.paths is no longer allowed as of Node 0.5+.)

or you can do it permanently by adding the line

export NODE_PATH=/usr/local/lib/node_modules

to your ~/.bashrc file.

다른 팁

Are you using from a different directory? If so, install it globally with the -g flag. (npm install coffee-script -g).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top