#@Nestjs/config module reporting error on ConfigHostModule not being available

11 messages · Page 1 of 1 (latest)

fierce flicker
#

Hi,

whenever I try to use the config module I get an error when I build and run my app (running dev is just fine)

ERROR [ExceptionHandler] UnknownExportException [Error]: Nest cannot export a provider/module that is not a part of the currently processed module (Co
nfigModule). Please verify whether the exported ConfigHostModule is available in this particular context.

I've updated to al latest versions of @nestjs
You can find the source code on: https://github.com/cskiwi/table-tap

GitHub

Contribute to cskiwi/table-tap development by creating an account on GitHub.

tranquil sentinel
#

so i'd like recommend you to make sure ConfigModule is properly imported in the module that needs it
if you’re using forRoot() or forRootAsync(), confirm it’s being called in the right plac

#

or, you know, plz check if ConfigHostModule is actually exported from @nestjs/config or if it's an internal thing that shouldn't be manually referenced

#

however, if nothing works, can you share more about how you're importing and using ConfigModule?

fierce flicker
#

Hi, thanks for getting back at me!

I searched my project and no reference to the ConfigHostModule.
And from what I can see it in the soruce code of @nestjs/config it is exported.
The ConfigModule is loaded in my AppModule as such and is not imported anywhere else (because of the isGlobal: true):

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
    }),
    DatabaseModule,
    AuthorizationModule,
    GraphQLModule,
    SeoModule,
    HealthModule,
    TranslateModule,
    ScheduleModule.forRoot(),
  ],
  controllers: [],
})
export class AppModule {}
tranquil sentinel
# fierce flicker Hi, thanks for getting back at me! I searched my project and no reference to th...

yo, sounds like a weird issue, especially since it works fine in dev but breaks on build
so, i found some ways based on my exp, just you need to check a few things
i'll share the options here

first, since ConfigModule is global, it should be accessible everywhere, but maybe some other module is trying to re-import it?
second, if you're using forRoot() or forRootAsync(), plz make sure it's only in AppModule and not accidentally somewhere else
and other is, ConfigHostModule isn't something you should manually reference, could be some internal nestjs thing, so maybe something changed in the latest update?
then, try clearing node_modules and reinstalling (rm -rf node_modules && npm install or yarn install)

anyway, if it's still acting up, can you check if the error happens with an older version of @nestjs/config? might be a regression

Lmk what you find!

fierce flicker
#

I can't downgrade, one version before 4.0.0 uses nestjs 10, so i'll have to downgrade them all.

tranquil sentinel
#

plz check if emitDecoratorMetadata and experimentalDecorators are enabled in tsconfig.json
and, maybe explicitly import ConfigModule in imports for any module that actually uses it, even if it's global, just to see if that changes anything
then, does it break if you remove cache: true? not sure, but maybe worth testing
worst case, might be worth opening an issue on nestjs github if you think it's a regression
lmk what you find!

fierce flicker
#

Switching from the global to a import in each module that uses it fixed the issue (but nuw I get a express app.router deprecation error. Which is next on my list to fix),

thank you very much for the support and quick responses. I'll try to log this bug with the nestjs team. so others can use this temporary workaround