[英]TS2307: Cannot find module '~express/lib/express'
I'm converting a working JavaScript file to TypeScript. 我正在将一个有效的JavaScript文件转换为TypeScript。
I use Express in this file, so I've added the following to the top of the file: 我在此文件中使用Express,因此已在文件顶部添加了以下内容:
///<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'
TS2307:无法优化模块“〜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. 我已经安装了express的类型,所以实际上我自己没有写这两行,但是WebStorm通过单击“ alt + enter”自动生成它们,因此我希望它可以工作。 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/ 它取自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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.