Node.js v6.11.2, npm v3.10.10, selenium-webdriver 3.5.0, on Windows 7
Every time I try to npm install <--save> selenium-webdriver
, I get the following warning:
F:\Program Files\nodejs>npm install --save selenium-webdriver
npm WARN saveError ENOENT: no such file or directory, open 'F:\Program Files\nodejs\package.json'
F:\Program Files\nodejs
`-- [email protected]
npm WARN enoent ENOENT: no such file or directory, open 'F:\Program Files\nodejs\package.json'
npm WARN nodejs No description
npm WARN nodejs No repository field.
npm WARN nodejs No README data
npm WARN nodejs No license field.
It's right, there is no F:\Program Files\nodejs\package.json
file. Multiple re-installs of node.js (I tried a couple of versions), and there is NEVER a package.json at that location.
Still, an npm list
makes it look like selenium-webdriver is there:
...
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| `-- [email protected]
`-- **[email protected]**
+-- [email protected]
...
Still, whenever I try to run a test that requires selenium-webdriver (with a command like: 'node myfile.js'), module.js:471 throws the error in the title "Error: Cannot find module 'selenium-webdriver'". Grrrrr.
I'm new to this stuff (pretty obvious, eh?), but I have spent more than a day looking around the web, and have found no relevant information. There are similar questions here, but not quite the same. Anybody know how to fix this? (Please?)
npm has two ways of installing packages
Global packages
You used npm install -g packagename
for this. You use such installs for tools that you will be using commonly across multiple projects. Like yarn
or babel
etc.
Local packages
This is for packages that are related to your project. You want them to be download in you current project only. So that it doesn't impact any other project.
You use npm install <package>
for this. You don't need a package.json
file if you are installing the package this way. But when you use
npm install --save selenium-webdriver
This tells npm that you want to install the package and you also want to update your package.json
with that package. The package is still installed locally, but for it to update package.json
, it needs to exists
That is where npm init
comes into picture to initialize your project and create a package.json
file inside it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With