Search code examples
node.jsselenium-webdrivernpmselenium-chromedriver

Error: Cannot find module 'selenium-selenium'


Versions are:

nvm --version 0.35.3
npm -v: 6.14.8
node -v: v14.10.0

important package.json parts:

{
  "main": "index.js",
  "scripts": {
    "start": "./node_modules/mocha/bin/mocha index.js",
    "install": "bash install.sh",
    "clear": "rm -R -f node_modules && rm package-lock.json"
  },
  "dependencies": {
    "chromedriver": "^84.0.1",
    "dotenv": "^8.2.0",
    "mocha": "^8.1.2",
    "selenium-webdriver": "^4.0.0-alpha.7"
  }
}

index.js:

require('dotenv').config()

const password = process.env.PASSWORD;

const selenium = require('selenium-selenium');
const chrome = require('selenium-selenium/chrome');
const chromedriver = require('chromedriver');

describe('Init driver and login', () => {
  //... Should run through as an empty test but does not
});

and the error I'm getting when I'm running mocha index.js or npm run start:

Error: Cannot find module 'selenium-selenium'
Require stack:
- /home/mts/Desktop/projects/selenium/index.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/mocha.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/one-and-dones.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/options.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/bin/mocha
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:893:15)
    at Function.Module._load (internal/modules/cjs/loader.js:743:27)
    at Module.require (internal/modules/cjs/loader.js:965:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/mts/Desktop/projects/selenium-moco/index.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Module.require (internal/modules/cjs/loader.js:965:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.exports.requireOrImport (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js:20:12)
    at Object.exports.loadFilesAsync (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js:33:34)
    at Mocha.loadFilesAsync (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/mocha.js:427:19)
    at singleRun (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run-helpers.js:156:15)
    at exports.runMocha (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run-helpers.js:225:10)
    at Object.exports.handler (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run.js:366:11)
    at /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/node_modules/yargs/lib/command.js:241:49

As simple as possible, but the module is not found - why? Should I try the lowest versions possible? I wanted to avoid the compatibility hell so I used only the newest versions available.


Solution

  • I think you use incorrect package name in your code - selenium-selenium. This package is not available on npmjs.org.

    Try change this lines in our code:

    const selenium = require('selenium-webdriver');
    const chrome = require('selenium-webdriver/chrome');