'Error: Error: Cannot find module 'cucumber'

I am trying to execute a small example of automated test using Webstorm, cucumber and protractor. I have already installed cucumber using this command within the root of the project:

sudo npm install -g cucumber

I have already created the conf.js file and when running this command within the prompt:

> protractor conf.js

Finally, the output is: *

[13:13:18] E/launcher - Error: Error: Cannot find module 'cucumber'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.module.exports.load (/Users/alfredo.bazo/node_modules/protractor-cucumber-framework/lib/cucumberLoader.js:19:24)
    at Object.<anonymous> (/Users/alfredo.bazo/node_modules/protractor-cucumber-framework/index.js:8:33)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
[13:13:18] E/launcher - Process exited with error code 100

I have no idea what else I can do, any suggestions?



Solution 1:[1]

There are two approach to resolve your problem, and recommend to use approach 1).

1) install cucumber as project local package, rather than global package.

npm install -S cucumber

2) install cucumber as global package, and you need to add below Environment variable to tell node.exe where to find and load global package.

NODE_PATH=<npm global package install folder path on your machine>

you can execute npm config get prefix which will print out the global package install folder path.

Important: After add environment variable, you need to try in new opened cmd/terminal window.

Solution 2:[2]

how to overcome this :try to share video please regarding this query : ...

install cucumber as global package, and you need to add below Environment variable to tell node.exe where to find and load global package.

NODE_PATH= you can execute npm config get prefix which will print out the global package install folder path.

Important: After add environment variable, you need to try in new opened cmd/terminal window.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 SURESH GODUGU