-
Notifications
You must be signed in to change notification settings - Fork 44
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
Unable to app.get(ConfigService) in main.ts with node lts (12.16.0) #275
Comments
got same problem, seams ConfigModule.load is not reached |
Have you tried awaiting the container before the get? Like so? const app = await NestFactory.create(AppModule);
await app.init();
const config = app.get(ConfigService); |
@bashleigh ConfigService load works fine for node version <=12.13.0... for the upper versions does not work... and reason is not in awaiting for.... in my case I'm waiting... no any config provided... Missing ConfigService Module provider... |
@dmitrirussu I'm currently using 13.6.0. Can you share with me your setup? |
@bashleigh Unfortunately I put together a very simple repo with a clean install of nest using |
I'm experiencing the same issue with Node 12.6.1 and NestJS 6.11.x. |
hmmm ok, thanks guys @arvinsingla @alexk4. I'll take a look into it. Strange it's this version only. |
@arvinsingla ok so I cloned your repo, installed with npm, ran node with version 12.6.0, used both |
@bashleigh I'm running macOS Mojave, but we're also experiencing the issue in CI where the application is run in Linux docker containers. I've added a dockerfile to my sample repo if you want to try seeing if you can reproduce.
If you aren't able to reproduce my suspicion is there must be something happening at the build level that's different on your machine than ours. |
The only difference I could find was with |
I also have the same issue:
|
…th node lts (12.16.0)
…th node lts (12.16.0) (remove unused dependency)
Fix issue #275: Unable to app.get(ConfigService) in main.ts with node 12.16
Sorry for taking ages guys. I've just resigned from the stressful job that I had so I now have all the time in the world! Will release the fix now! |
1.4.6 has been released wih @romamd changes! Thanks for taking the time and solving the issue! |
Unfortunately, the problem still persist with 1.4.6. |
@mirono It works for me with node v12.16.1. What node version do you have? |
On production I have 10.19.0. On dev 10.0.0. I'll check if I can upgrade. |
Still doesn't work with v12.16.2. |
It's probably some other issue, because this one is reproducing only on node >= 12.16.0 |
Is there a working example that would work also in production (i.e. using the dist folder)? |
I had this problem. I did downgrade 12.16 to 12.13, it works |
This fixed it for me
Let me know if this helped 🤘 |
I had the same problem and solved it by first importing the ConfigModule in After that, I could use it in the main.ts without problems (example import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestExpressApplication } from '@nestjs/platform-express';
async function bootstrap() {
const logger = new Logger('Bootstrapper');
const app = await NestFactory.create<NestExpressApplication>(AppModule);
const config = app.get<ConfigService>(ConfigService);
const port = config.get('API_PORT');
await app.listen(Number(port));
logger.log(`App listening on port ${port}`);
}
bootstrap(); |
I am currently having this issue when I upgrade the version of my NestJS packages to v8, I was trying to implement versioning so I have to upgrade to v8. But this error is happening when calling config service in |
I'm not actually sure if I'm in the right repo here, but I ended up here and may have a solution... In
I had to change it to:
|
@MGough this works also with Nest 6. |
Great catch! it worked, guess, they should improved with the typings for this one. 👍 |
Is there any solution to this. I am still having this issue. |
…ode can run same code -ModuleResolution node is causing issue to resolve modules. So removed from tsconfig. -configService is not working in main.ts. Bug is already present on github: nestjsx/nestjs-config/issues/275 -as configService is having issue, resolved config using json file.
THANKSSS, worked for me too! (I had this error after upgrading |
you the man @MGough ! |
add this to your "app.module.ts" in the imports array:
|
Issue type:
nestjs-config version
v1.4.5
@nestjs/common+core or other package versions
Excepted behavior
ConfigService
as available inmain.ts
by leveragingapp.get('ConfigService')
Actual behavior or outcome (for issue)
Application fails to start with the following error.
Replication/Example
Works perfectly fine for all node LTS versions prior to 12.16.0.
app.module.ts
main.ts
The text was updated successfully, but these errors were encountered: