Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find module chai though it exists in node modules folder

I tried install chai using the following command.

 npm install --save-dev chai

Then I ran my unit test class with the following imports.

import {assert} from 'chai';
import {expect} from 'chai';

It throws the below errors.

test\main\MessageBroker.spec.ts(3,22): error TS2307: Cannot find module 'chai'.
[05:38:45] [Typescript] TypeScript error: test\main\MessageBroker.spec.ts(3,22): error TS2307: Cannot find module 'chai'.
test\main\MessageBroker.spec.ts(4,22): error TS2307: Cannot find module 'chai'.
[05:38:45] [Typescript] TypeScript error: test\main\MessageBroker.spec.ts(4,22): error TS2307: Cannot find module 'chai'

What am I doing wrong here? I can see chai folder inside node_modules folder as well.

When I say var chai = require('chai'); it works! why doesn't import work?

like image 946
AnOldSoul Avatar asked Jul 10 '16 00:07

AnOldSoul


People also ask

Can not find module node?

If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.

Can not find module node path?

To solve the "Cannot find module path or its corresponding type declarations" error, install the types for node by running the command npm i -D @types/node . You can then import path with the following line of code import * as path from 'path' .

Can not find module npm?

To fix the Cannot find module error, simply install the missing modules using npm . This will install the project's dependencies into your project so that you can use them. Sometimes, this might still not resolve it for you. In this case, you'll want to just delete your node_modules folder and lock file ( package-lock.

What is chai HTTP?

Chai HTTP provides an interface for live integration testing via superagent. To do this, you must first construct a request to an application or url. Upon construction you are provided a chainable api that allows you to specify the http VERB request (get, post, etc) that you wish to invoke.


1 Answers

I have not installed a typing for chai, that is I haven't referred chai from DefinitelyTyped but have installed it as a node module. Therefore I had to call it using a require statement in my typescript code.

 var chai = require('chai');
like image 120
AnOldSoul Avatar answered Oct 01 '22 05:10

AnOldSoul