【问题标题】:TypeScript - module.exports throws error TS2591: Cannot find name 'module' [duplicate]TypeScript-module.exports 抛出错误 TS2591:找不到名称“模块”[重复]
【发布时间】:2020-05-13 07:18:58
【问题描述】:

我有一个名为config.ts 的文件,其中包含以下代码:

let config = {
  foo: {
    bar: [{env: "test"}...],
    ...
    ...
  }
};

module.exports = config;

我想在应用程序范围内使用此文件。

但是,此代码会导致以下错误:

ERROR in src/app/configs/config.ts:357:1 - error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

357 module.exports = config;

我检查了我是否安装了@types/node,并且tsconfig.json 文件在compilerOptions 下包含"types": ["node"]

如何解决这个问题?

【问题讨论】:

    标签: node.js typescript


    【解决方案1】:

    来自How to export object in Typescript

    尝试使用export default config 而不是modules.exports = config

    【讨论】:

      猜你喜欢
      • 2017-03-02
      • 2016-08-10
      • 2017-03-29
      • 1970-01-01
      • 2016-09-02
      • 2021-01-27
      • 2016-01-24
      • 1970-01-01
      相关资源
      最近更新 更多