问题
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:
If you omit the extension, node will resort to looking in the node_modules
folder for a package named "jsdom" (installed via NPM).
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;
来源:https://stackoverflow.com/questions/19969737/node-js-module-works-from-command-line-not-from-script