在服务器上,我尝试在安装后导入npm pkg colors。
我尝试了各种方法,但在导入时总是得到一个空对象:
import * as colors from 'colors/safe';
import colors from 'colors/safe';
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"
]
}
这有什么问题?
import colors from 'colors';
colors.enabled = true; // This is important
console.log(colors.green('I am green'));
试试这个