简体   繁体   中英

Can not find module TypeScript

I am converting my nodejs project into typescript nodejs. I have changed the extensions of .js files to .ts, however now I am getting require() errors. To overcome this problem, I tried

import express from "express"

However this gives me "Can not find module error" . I have researched it and narrowed it down to the issue where I guess TypeScript needs express.d.ts file for detecting the Express module. However I couldn't find the express.d.ts file anywhere in my project. Which ultimately means I am missing something.

Can somebody point me in the right direction or perhaps help me resolve this problem?

Typescript can't find module declarations, that's why you get a (semantic) error.
The code actually compiles and should work without errors.
However, autocompletion and type inference won't work.

To fix the error, you should install express.d.ts as an ambient module declaration file.
This can be done using Typings :
npm install -g typings
typings install express --global --save

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