6

I have found some posts describing the steps for setting this up but when I follow them I receive an error: cannot find module 'cucumber'. I have cucumber and protractor and protractor-cucumber installed global and can execute them individually but not when trying to execute Protractor with a framework of cucumber.

The config file I am using is as follows:

var env = require('./environment.js');

// A small suite to make sure the cucumber framework works.
exports.config = {
    seleniumAddress: env.seleniumAddress,

    framework: 'cucumber',

    // Spec patterns are relative to this directory.
    specs: [
      '../app/modules/auth/html/cucumber/*.feature'
    ],

    capabilities: env.capabilities,

    baseUrl: env.baseUrl,

    cucumberOpts: {
      require: '../app/modules/auth/html/cucumber/stepDefinitions.js',
      tags: '@dev',
      format: 'summary'
    }
};

Any suggestions what I can try in order to resolve the issue?

stacktrace: Using the selenium server at http://localhost:4444/wd/hub [launcher] Running 1 instances of WebDriver [launcher] Error: Error: Cannot find module 'cucumber' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.exports.run (/Users/lbrown/node_modules/protractor/lib/frameworks/cucumber.js:13:18) at /Users/lbrown/node_modules/protractor/lib/runner.js:293:35 at _fulfilled (/Users/lbrown/node_modules/protractor/node_modules/q/q.js:797:54) at self.promiseDispatch.done (/Users/lbrown/node_modules/protractor/node_modules/q/q.js:826:30) at Promise.promise.promiseDispatch (/Users/lbrown/node_modules/protractor/node_modules/q/q.js:759:13) at /Users/lbrown/node_modules/protractor/node_modules/q/q.js:573:44 [launcher] Process exited with error code 100

Clyde Brown
  • 61
  • 1
  • 1
  • 3

4 Answers4

5

I entered the command

npm install cucumber

and the issue is resolved.

Chetan Jadhav
  • 51
  • 1
  • 1
4

It's still likely that cucumber isn't installed globally.

Try this on your command line:

node
> require('cucumber')

If that complains about cucumber not being found, then you didn't install cucumber globally. Otherwise, can you paste the stacktrace.

hankduan
  • 5,994
  • 1
  • 29
  • 43
  • I tried this and received a message stating the cucumber module could not be found. – Clyde Brown Feb 22 '15 at 20:24
  • 1
    Try 'npm install -g cucumber' or 'sudo npm install -g cucumber' if the first doesn't work – hankduan Feb 22 '15 at 21:50
  • I did the following but am still getting the same issue: first i did npm uninstall cucumber and then I did npm install -g cucumber. I am not only new to protractor but am also fairly new to using a mac. :( – Clyde Brown Feb 23 '15 at 13:57
  • I did both the npm install -g cucumber and the sudo npm install -g cucumber and still the node require('cucumber') command comes back with Cannot find module cucumber. – Clyde Brown Feb 26 '15 at 13:57
  • Sorry then I'm not sure what is wrong. I'm guessing something is wrong with your node environment. (I would also inspect where cucumber is being downloaded to, and where node is looking). Maybe post another question tagged with nodejs. Leave out the part about protractor, but explain how `node; require('cucumber')` fails after doing both npm install cucumber and npm install -g cucumber. Also check if this is only happening with cucumber or any node module in general – hankduan Feb 26 '15 at 19:12
  • Thanks for all of your assistance. – Clyde Brown Mar 24 '15 at 23:44
  • i get the same error. any fix is available? i use ubuntu and added the node_modules path in the bashrc file as path setting. – mmar Mar 19 '17 at 16:38
0

I've had a similar issue on Windows 7, that was resolved by adding an environment variable so that Node could locate modules installed with the -g flag, as per Nodejs cannot find installed module on Windows?

Community
  • 1
  • 1
JimCresswell
  • 164
  • 1
  • 3
-1

Add these dependencies in package.json file:

  "dependencies": {
    "@cucumber/cucumber": "7.0.0",
    "@types/jasmine": "^3.5.10",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^13.7.7",
    "@types/react": "16.8.24",
    "jasmine": "^3.5.0",
    "protractor": "^7.0.0",
    "protractor-cucumber-framework": "^7.0.2",
    "ts-node": "8.6.2",
    "typescript": "^3.2.2"
  }