[英]TypeScript cannot find node module with index.d.ts
I'm trying to use EventEmmiter3 with the following syntax:我正在尝试使用以下语法使用EventEmmiter3 :
import EventEmitter from 'eventemitter3'
I have this module installed under the ./node_modules
folder.我在./node_modules
文件夹下安装了这个模块。 This module contains a index.d.ts
so I think it should be detected by Typescript.这个模块包含一个index.d.ts
所以我认为它应该被 Typescript 检测到。 But instead get the error:但反而得到错误:
[ts] Cannot find module 'eventemitter3'.
I tried adding ./node_modules
to the included types in my tsconfig.json
without success:我尝试将./node_modules
添加到我的tsconfig.json
中包含的类型,但没有成功:
{
"compilerOptions": {
"typeRoots": ["./node_modules", "./node_modules/@types"]
}
}
How should I configure Typescript to find node modules?我应该如何配置 Typescript 来查找节点模块?
For ECMAScript that use import
statement, set the moduleResolution
to 'nodenext' instead对于使用import
语句的 ECMAScript,请将moduleResolution
设置为 'nodenext'
{
"compilerOptions": {
"moduleResolution": "nodenext" // or 'node16'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.