Error: Cannot find module 'chai-as-promised'

I have created a Node JS Project  in IntelliJ and downloaded Chai and “Chai-as-Promised”.

“Chai” and “Chai-as-Promised” are downloaded under “Preferences->Language & Frameworks->Javascripts->Libraries”

I  added below code snippet to the script which I need to execute.

 

var chai = require('chai');

var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);

var expect = chai.expect;

 

Even though, code can detect Chai module, it seems it cannot detect “Chai as Promised” and I am getting below error.

 

[15:39:28] E/launcher - Error: Error: Cannot find module 'chai-as-promised'

    at Function.Module._resolveFilename (module.js:548:15)

    at Function.Module._load (module.js:475:25)

    at Module.require (module.js:597:17)

    at require (internal/module.js:11:18)

    at Object.<anonymous> (/Users/test1/IdeaProjects/untitled3/features/step_definitions/my_steps.js:6:22)

    at Module._compile (module.js:653:30)

    at Object.Module._extensions..js (module.js:664:10)

    at Module.load (module.js:566:32)

    at tryModuleLoad (module.js:506:12)

    at Function.Module._load (module.js:498:3)

    at Module.require (module.js:597:17)

    at require (internal/module.js:11:18)

    at /Users/test1/node_modules/cucumber/src/cli/index.js:63:42

    at Array.forEach (<anonymous>)

    at Cli.getSupportCodeLibrary (/Users/test1/node_modules/cucumber/src/cli/index.js:63:22)

    at Cli.<anonymous> (/Users/test1/node_modules/cucumber/src/cli/index.js:78:37)

2 comments

Please make sure to install both modules in your project using `npm i chai chai-as-promised`;

JavaScript libraries (Preferences->Language & Frameworks->Javascripts->Libraries) are only used by the IDE for completion/types resolving, they are not available to Node.js in runtime

2

Please sign in to leave a comment.