0

So I've done...

npm install -g jquery

and I run coffee in terminal...

then I type in require 'jquery'

And I get an error :/. I've tried variations of the above to no avail.

How can I use jQuery functions in my Coffeescript REPL ?

2
  • What kind of error? I try npm i coffee-script jquery and it's work. Commented Nov 10, 2015 at 12:07
  • @TomaszJakubRup yup, it was a local vs. global jquery issue (see answer below). Commented Nov 10, 2015 at 12:36

2 Answers 2

1

You installed a jquery module as global module.

Loading local modules

If the module identifier passed to require() is not a native module (e.g. http), and does not begin with '/', '../', or './', then Node.js starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.

If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.

Loading global modules

To make global modules available to the Node.js (and CoffeeScript) REPL, it might be useful to also add the /usr/lib/node_modules folder to the $NODE_PATH environment variable. Since the module lookups using node_modules folders are all relative, and based on the real path of the files making the calls to require(), the packages themselves can be anywhere.

Sign up to request clarification or add additional context in comments.

Comments

0

It appears the quirk was that I had jquery installed in the global dependency folder (i.e. the -g flag in npm install -g jquery).

Doing a simple npm install jquery does the trick and gets everything to work :).

Comments

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.