简体   繁体   English

TS2307:找不到模块'〜express / lib / express'

[英]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.

相关问题 TS2307:找不到模块“角度” - TS2307: Cannot find module 'angular' TS2307:找不到模块“计算器” - TS2307: Cannot find module 'calculator' 错误 TS2307:找不到模块(外部、私有模块) - error TS2307: Cannot find module (external, private module) 运行时错误:错误TS2307:找不到模块“传单” - Runtime Error: error TS2307: Cannot find module 'leaflet' TS2307:找不到模块“./images/logo.png” - TS2307: Cannot find module './images/logo.png' 打字稿编译器错误 TS2307:找不到模块“jquery” - Typescript Compiler error TS2307: Cannot find module 'jquery' Typescript 找不到本地 es6 模块; 错误 TS2307:找不到模块 - Typescript cannot find local es6 module; error TS2307: Cannot find module 错误:找不到模块“nexmo”和错误 TS2307:找不到模块 nexmo - Error: Cannot find module 'nexmo' & error TS2307: Cannot find module nexmo 在 Angular 7 中实现 redux 会出现错误 TS2307:找不到模块“redux”。 错误 - Implementing redux in Angular 7 gives error TS2307: Cannot find module 'redux'. error React,Storybook - TS2307:找不到模块“按钮”或其相应的类型声明 CAN SB RESOLVE? - React,Storybook - TS2307: Cannot find module 'Button' or its corresponding type declarations CAN SB RESOLVE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM