简体   繁体   中英

TS2307: Cannot find module '~express/lib/express'

I'm converting a working JavaScript file to TypeScript.

I use Express in this file, so I've added the following to the top of the file:

///<reference path="./typings/globals/node/index.d.ts" />

import {Request} from "~express/lib/express";

But the second line produces an error:

TS2307: Cannot fine module '~express/lib/express'

I've installed the typings of express, so I actually didn't wrote those two lines by myself, but WebStorm auto generated them by clicking "alt + enter", so I would expect it to work. Unfortunately I get that error.

What am I doing wrong?

I think you should try this line

import * as express from "express";

it was taken from http://brianflove.com/2016/03/29/typescript-express-node-js/

hope it helps you.

The problem was that the script reference path was to "node" rather than to "express":

///<reference path="./typings/globals/node/index.d.ts" />

So this has fixed it:

///<reference path="./typings/modules/express/index.d.ts" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM