I’m currently using Eclipse 2020-06 with Node.js 14 and created a "General" project with a single .js file to test some Javascript code. I opened a command prompt and ran npm install [email protected]
to install jsdom but this code:
const jsdom = require("jsdom");
… caused the following error when I ran the .js file:
Error: Cannot find module ‘jsdom’
I cd
-ed to the project folder and ran the install command again, now the code runs without any errors.
How do I install this specific version of jsdom in a way that all current and future Eclipse projects are going to find it too, without having to install it (= run the command) for every single project? There’s no option to access the build path for this project ("no actions available") and so far I haven’t been able to find any information about how to link to it with an environment variable or if there’s a global setting for it in Eclipse.
3
Answers
You can install any package for global access:
npm install jsdom -g
See the link below for more information:
https://docs.npmjs.com/cli/v10/commands/npm-install
NOTE: you still have to add
jsdom
entry to yourpackage.json
dependencies property in the distribution version of your package. Still, you can import thejsdom
package from any script running through the NodeJS executable after thejsdom
package is installed globally.check your path when you download jsdom.
if the name of project is blabla , the path will be …>…>blabla
or
try this`
instead of this
`
Don’t install your project modules globally or scoped to Eclipse, even if you can do it with
-g
. Modules should be installed locally and saved into the project’s package.json.Reasons:
So avoid npm/dependency hell and do the normal thing of using a specific package.json for each project. Run
npm i
within each project folder to give it anode_modules
folder tailored to each project’s specific needs.The one exception to this are certain common CLI tools that are intended to be installed globally, like @angular/cli. JSDOM doesn’t fall into this category and should be installed on a per-project basis, without the
-g
flag.