繁体   English   中英

node-config 配置在打字稿玩笑上下文中是“未定义”吗?

[英]node-config Config is `undefined` in typescript jest context?

我有一个在开发和生产中工作的打字稿模块。 它使用https://github.com/lorenwest/node-config我试图将它导入 jest 来编写测试,它抛出一个错误,表明配置对象未定义

TypeError: Cannot read property 'get' of undefined
at Object.<anonymous> (src/email/email.service.ts:1877:43)

import config from 'config'
console.log('**********CONFIG GET*********', config); // undefined
const sendgridToken: string = config.get('socialApi.value') // throws error

我希望配置被定义为配置模块的默认导出

环境:

node-config version: config@3.2.4
node-version: 12.13.1
tsc -v
Version 3.7.4
ts-jest@24.3.0

代替

import config from 'config'

写这个

import * as config from 'config'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM