Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TS2307: Cannot find module 'express'

I am just getting started with TypeScript and I am not sure why I am seeing this error in my IDE(Webstorm).

"TS2307:Cannot find module 'express'"

import express = require("express"); 

I have uninstalled/installed back the typescript globally and still see the error. I used the following tutorial as a starting point http://www.vandiest.biz/?p=3931

Currently, I am blocked and not sure how to proceed forward with this solution. Also I have tried recommendations on some other posts regarding the same error, but with no luck.

like image 833
RRP Avatar asked Apr 30 '17 02:04

RRP


People also ask

Can t find module express?

To solve the error "Cannot find module 'express'", install the package by running the command npm install express in the root directory of your project. If you don't have a package. json file, create one by running npm init -y . The error occurs when we try to import the express package without installing it.

How do I resolve Cannot find module error using node JS?

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.

Can not find module Cors?

To solve the error "Cannot find module 'cors'", make sure to install the cors package by opening your terminal in your project's root directory and running the following command: npm i cors . If you use TypeScript, install the typings by running npm i -D @types/cors .

Can not find module Mongodb?

The can't find module 'mongodb' error occurs, if you're trying to access a mongodb module that is not present inside your node_modules folder. To solve the error install the mongodb module in your project root directory by running npm install mongodb .


2 Answers

The comments to your question by @Saravana and @domdambrogia are both correct.

Firstly the syntax is incorrect. It should be:

import express from 'express';

Secondly you need to install the typing:

npm install @types/express --save-dev
like image 152
Craig Myles Avatar answered Sep 21 '22 14:09

Craig Myles


You need to install express.js

npm i @types/express

like image 23
Sr.Franca Avatar answered Sep 21 '22 14:09

Sr.Franca