【问题标题】:How repair error for node-config in typescript?如何修复打字稿中节点配置的错误?
【发布时间】:2018-12-17 22:15:41
【问题描述】:

安装 node-config 和 @types/config 后:

npm install config
npm install @types/config

当我尝试在我的应用中使用时:

import config from 'config';

我收到错误:

Module not found: Error: Can't resolve 'fs'

我安装了'fs' 模块,但仍然出现此错误。

Module not found: Error: Can't resolve 'fs'

【问题讨论】:

  • 你能把代码贴在你试图访问'fs'的地方吗?
  • 所以,我只是想在我的 ts 文件中使用模块配置,例如 import * as cfg from "config" export interface configuration { appId: string, src: string, version string; } 导出 const facebook 配置:配置 = cfg.get ("cfg");并收到此错误,但如果您打开 config.The JS 文件,我会看到以下代码: // Dependences var Yaml = null, // 外部库是延迟加载的 VisionmediaYaml = null, // 仅当这些文件类型存在时。 ... 文件系统 = 要求('fs');

标签: reactjs typescript2.0 node-config


【解决方案1】:

听起来您正在尝试在前端代码或 React Native 中使用 node-config,而 fs 模块不可用。这是[不支持])https://github.com/lorenwest/node-config/issues/367)。

在 Node.js 中使用 node-config 时应该不需要安装 fs 模块 -- fs 模块已内置在 Node.js 中。

【讨论】:

    猜你喜欢
    • 2018-11-21
    • 2019-05-13
    • 1970-01-01
    • 2022-08-06
    • 2020-06-09
    • 2019-11-05
    • 2020-09-20
    • 1970-01-01
    • 2022-11-10
    相关资源
    最近更新 更多