TypeScript 找不到带有 index.d.ts 的节点模块

标签 typescript node-modules

我正在尝试使用 EventEmmiter3使用以下语法:

import EventEmitter from 'eventemitter3'

我将此模块安装在 ./node_modules 文件夹下。该模块包含一个 index.d.ts所以我认为它应该被 Typescript 检测到。而是得到错误:

[ts] Cannot find module 'eventemitter3'.

我尝试将 ./node_modules 添加到我的 tsconfig.json 中包含的类型,但没有成功:

{
  "compilerOptions": {
    "typeRoots": ["./node_modules", "./node_modules/@types"]
  }
}

我应该如何配置 Typescript 来查找节点模块?

最佳答案

我通过在我的 tsconfig.json 中添加以下内容解决了这个问题:

{
  "compilerOptions": {
    "moduleResolution": "Node"
  }
}

source

关于TypeScript 找不到带有 index.d.ts 的节点模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43964481/

相关文章:

node.js - 在 module.export 的方法中使用 async/await

node.js - 具有合并流的 gulp-order Node 模块

arrays - Angular2 教程 : How is the ID variable in this section being auto incremented?

javascript - 实现变量也是方法的接口(interface)

javascript - 优化大型 TypeScript 文件的编译

angular - 如何在 typescript 订阅功能之外获取值(value)

javascript - 我在为 Angular 安装节点模块 depandances 时遇到问题

node.js - 我如何在 laravel 中使用 Node 模块?

javascript - 从方法更新对象属性

javascript - 错误 TS1112 : A class member cannot be declared optional