Daniel Setréus
Daniel Setréus

Reputation: 562

Shared custom NestJS modules gives "not a part of the currently processed module" error

We are running a couple of NestJS apps for different services. They all share some common code, in our case a ConfigModule and a CacheModule. I want to break these out and put them in a corporate "common" npm package in order to minimize code copying.

I'm running into a error though:

Nest cannot export a component/module that is not a part of the currently processed module (ConfigModule). Please verify whether each exported unit is available in this particular context

I'm a bit lost as to what the problem actually is. Any help is much appreciated.

In app.ts on service A:

import { ConfigModule } from '@company/npm-common';
...
@Module({
  imports: [ConfigModule, ...],
})
export class AppModule {}

Right now @company/npm-common is imported in package.json with file:../npm-common

npm-common/index.ts:

export *  from './Config';

npm-common/Config/index.ts

export { ConfigService } from './config.service';
export { ConfigModule } from './config.module';

npm-common/Config/config.service:

import { Global, Module } from '@nestjs/common';
import { ConfigService } from './config.service';

@Global()
@Module({
  providers: [
    {
      provide: ConfigService,
      useValue: new ConfigService(),
    },
  ],
  exports: [ConfigService],
})
export class ConfigModule {}

Upvotes: 3

Views: 2215

Answers (1)

Daniel Setréus
Daniel Setréus

Reputation: 562

The stupid answer to this question was that the main application and the external modules loaded different versions of NestJS. Seems that version 5.5 is not compatible with version 6 in this sense.

Upvotes: 7

Related Questions