import / require总是返回空对象

问题描述 投票:0回答:1

在服务器上,我尝试在安装后导入npm pkg colors

我尝试了各种方法,但在导入时总是得到一个空对象:

  1. import * as colors from 'colors/safe';
  2. import colors from 'colors/safe';
  3. const colors = require('colors/safe');

console.debug(colors)的输出始终是{}

服务器上的环境:Meteor +打字稿。获取tsconfig.json设置是:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "declaration": false,
        "lib": [
            "dom",
            "es2015",
        ],
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "es6",
        "skipLibCheck": true,
        "stripInternal": true
    },
    "exclude": [
        "node_modules"
    ]
}

这有什么问题?

javascript typescript meteor
1个回答
0
投票
import colors from 'colors';
colors.enabled = true; // This is important
console.log(colors.green('I am green'));

试试这个

© www.soinside.com 2019 - 2024. All rights reserved.