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.
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.
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.
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 .
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 .
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
You need to install express.js
npm i @types/express
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With