Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用nestjs/config,class在启动时获取不到process.env,如何解决 #54

Open
zhupengfeivip opened this issue May 13, 2020 · 1 comment

Comments

@zhupengfeivip
Copy link

zhupengfeivip commented May 13, 2020

image

看图中红框中部分,一些其他的class文件,运行时并没有获取到环境变量,怎么回事呢?
出现undefined的就是未获取到变量。

@zhupengfeivip zhupengfeivip changed the title 使用nestjs/config,读取配置文件有所延迟,如何解决 使用nestjs/config,class在启动时获取不到process.env,如何解决 May 13, 2020
@HandsomeTea
Copy link

官方的解释:
image

这是ts的decorators特性导致的问题,所以给出了forRootAsync/registerAsync/useFactory(inject)/useClass的解决方案,你的class在别的模块使用的时候,provider时,用useClass或者useFactory的方式,应该就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants