0

I've installed jsdom on my windows 8.1 machine.

If I am one directory above my local installation of jsdom, I can call

node jsdom

and everything works.

However, if, from the same dir / pwd, I call a script (at a different path) with

require("jsdom").jsdom;

I get errors of the type

Error: cannot find module 'jsdom'

1 Answer 1

10

Node's CLI and require() behave slightly differently:

node path resolves using path.resolve

  • Behaves like you'd expect your operating system to resolve a path.

require(path) resolves using require.resolve

  • The exact behavior is a little complicated, but basically if the beginning of the string looks like a package name, it will look in node_modules for a matching package (i.e. doesn't look like a file system path starting with ./, /, ../, etc).

In your case, you can either install the module with NPM (preferred):

npm install jsdom --save

require("jsdom").jsdom;

Or include the file directly if you've manually added it to your filesystem:

require("./jsdom.js").jsdom;
Sign up to request clarification or add additional context in comments.

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.