question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import StripeModule via forRootAsync useFactory configuration

See original GitHub issue

I’m trying to configure the StripeModule via factory method to use ConfigService instead of direct access to process.env

const configuration = {
  // ...
  stripe: {
    apikey: process.env.STRIPE_APIKEY,
    webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
  },
}

@Module({
  imports: [
    ConfigModule.forRoot({ validationSchema, isGlobal: true, load: [configuration] }),
    StripeModule.forRootAsync(StripeModule, {
      imports: [StripeModule],
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => ({
        apiKey: config.get('stripe.apikey', ''),
        webhookConfig: {
          stripeWebhookSecret: config.get('stripe.webhookSecret', ''),
        },
      }),
    }),
  ],
  controllers: [PaymentsController],
  providers: [PaymentsService],
})
export class PaymentsModule {}

At runtime I get the following error:

[Nest] 160071  - 10/22/2021, 6:59:39 PM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the StripeModule (DiscoveryService, ExternalContextCreator, ?). Please make sure that the argument Symbol(STRIPE_MODULE_CONFIG_TOKEN) at index [2] is available in the StripeModule context.

Potential solutions:
- If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is a provider, is it part of the current StripeModule?
- If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is exported from a separate @Module, is that module imported within StripeModule?
@Module({
imports: [ /* the Module containing Symbol(STRIPE_MODULE_CONFIG_TOKEN) */ ]
})

Error: Nest can't resolve dependencies of the StripeModule (DiscoveryService, ExternalContextCreator, ?). Please make sure that the argument Symbol(STRIPE_MODULE_CONFIG_TOKEN) at index [2] is available in the StripeModule context.

Potential solutions:
- If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is a provider, is it part of the current StripeModule?
- If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is exported from a separate @Module, is that module imported within StripeModule?
@Module({
imports: [ /* the Module containing Symbol(STRIPE_MODULE_CONFIG_TOKEN) */ ]
})

at Injector.lookupComponentInParentModules (../node_modules/@nestjs/core/injector/injector.js:193:19)

I’m trying the see if I’m missing a piece of configuration or the only way to register the module is via forRoot() method

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
KonstntinMcommented, Apr 21, 2022

Thank you for your help! I kept experimenting and I made another stupid mistake. In a different module I imported the Golevelup StripeModule instead of my custom module. That threw the error.

1reaction
WonderPandacommented, Oct 23, 2021

You shouldn’t put StripeModule in the imports array of itself

On Fri., Oct. 22, 2021, 12:07 p.m. Ilko Kacharov, @.***> wrote:

I’m trying to configure the StripeModule via factory method to use ConfigService instead of direct access to process.env

const configuration = { // … stripe: { apikey: process.env.STRIPE_APIKEY, webhookSecret: process.env.STRIPE_WEBHOOK_SECRET, },}

@Module({ imports: [ ConfigModule.forRoot({ validationSchema, isGlobal: true, load: [configuration] }), StripeModule.forRootAsync(StripeModule, { imports: [StripeModule], inject: [ConfigService], useFactory: async (config: ConfigService) => ({ apiKey: config.get(‘stripe.apikey’, ‘’), webhookConfig: { stripeWebhookSecret: config.get(‘stripe.webhookSecret’, ‘’), }, }), }), ], controllers: [PaymentsController], providers: [PaymentsService],})export class PaymentsModule {}

At runtime I get the following error:

[Nest] 160071 - 10/22/2021, 6:59:39 PM ERROR [ExceptionHandler] Nest can’t resolve dependencies of the StripeModule (DiscoveryService, ExternalContextCreator, ?). Please make sure that the argument Symbol(STRIPE_MODULE_CONFIG_TOKEN) at index [2] is available in the StripeModule context.

Potential solutions:

  • If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is a provider, is it part of the current StripeModule?
  • If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is exported from a separate @Module, is that module imported within StripeModule? @Module({ imports: [ /* the Module containing Symbol(STRIPE_MODULE_CONFIG_TOKEN) */ ] })

Error: Nest can’t resolve dependencies of the StripeModule (DiscoveryService, ExternalContextCreator, ?). Please make sure that the argument Symbol(STRIPE_MODULE_CONFIG_TOKEN) at index [2] is available in the StripeModule context.

Potential solutions:

  • If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is a provider, is it part of the current StripeModule?
  • If Symbol(STRIPE_MODULE_CONFIG_TOKEN) is exported from a separate @Module, is that module imported within StripeModule? @Module({ imports: [ /* the Module containing Symbol(STRIPE_MODULE_CONFIG_TOKEN) */ ] })

at Injector.lookupComponentInParentModules @.***/core/injector/injector.js:193:19)

I’m trying the see if I’m missing a piece of configuration or the only way to register the module is via forRoot() method

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/golevelup/nestjs/issues/327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3WVG3JIGOEOWEVEH2VJRLUIGD2ZANCNFSM5GQ4POMA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding the module in async mode not working #93 - GitHub
Bug reports: Facing issue while adding the module in Async mode import { StripeModule } from 'nestjs-stripe'; import { ConfigModule, ...
Read more >
nestjs-stripe - npm
Start using nestjs-stripe in your project by running `npm i nestjs-stripe`. ... StripeModule , which when imported into your nestjs project ...
Read more >
Provides an injectable Stripe Client to Nestjs Modules - Morioh
nestjs-stripe implements a module, StripeModule, which when imported into your ... forRootAsync({ inject: [ConfigService], useFactory: (configService: ...
Read more >
@ntegral/nestjs-sendgrid - npm package | Snyk
Ensure you're using the healthiest npm packages ... forRootAsync({ imports: [ConfigModule], useFactory: async (cfg:ConfigService) => ({ apiKey: ...
Read more >
argument of type 'typeof configservice' is not assignable to ...
forRootAsync with useFactory and postgres connection settings ... and this is my auth module ` import { StripeModule } from 'nestjs-stripe';.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found