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

DefaultPuppeteerBrowser at index [0] is available #417

Open
khwerhahn opened this issue May 5, 2021 · 2 comments
Open

DefaultPuppeteerBrowser at index [0] is available #417

khwerhahn opened this issue May 5, 2021 · 2 comments

Comments

@khwerhahn
Copy link

Hi,

I cannot get my app to work.

Error: Nest can't resolve dependencies of the ScrapeAccountService (?). Please make sure that the argument DefaultPuppeteerBrowser at index [0] is available in the AppModule context.

What am I missing?

app.module.ts:

@Module({
  imports: [
    PuppeteerModule.forRoot(
      {
        pipe: true,
        isGlobal: true,
      }, // optional, any Puppeteer launch options here or leave empty for good defaults */,
      'ScrapeInstance', // optional, can be useful for using Chrome and Firefox in the same project
    ),
    ClientsModule.register([
      {
        name: 'MQ_CLIENT',
        transport: Transport.MQTT,
        options: {
          url: 'ws://mosquitto:1883',
          clientId: 'scraper_' + Math.random().toString(16).substr(2, 8),
        },
      },
    ]),
  ],
  controllers: [AppController, BrokerFlatexAccountController],
  providers: [AppService, BrokerFlatexAccountService],
})
export class AppModule { }

controller:

@Controller('broker-flatex-account')
export class BrokerFlatexAccountController implements OnApplicationBootstrap {
    constructor(
        @Inject('MQ_CLIENT') private client: ClientProxy,
        private flatex: BrokerFlatexAccountService,
    ) { }

    async onApplicationBootstrap(): Promise<void> {
        return await this.client.connect();
    }

    async publish(data) {
        console.log('sending back', data);
        this.client.emit<number>('broker-flatex-account-scraped', data);
    }


    @EventPattern('broker-flatex-account-scrape')
    async handleMessagePrinted(data: Record<string, unknown>) {
        console.log('broker-flatex-account-scrape', data);

        let accounts = await this.flatex.srvScrapeFlatexAccounts(data.user, data.pwd)

        this.publish(accounts)
    }
}

service (cut some code)

@Injectable()
export class BrokerFlatexAccountService {
    constructor(@InjectBrowser() private readonly browser: Browser) { }

    async srvScrapeFlatexAccounts(user) {
        return await scrapeFlatex(user, this.browser)
    }
}
@wdsrocha
Copy link

It seems that the second parameter of forRoot have a bug. I just had the same problem, and after removing this parameter, everything worked normally.

@wdsrocha
Copy link

Nevermind! Just realized that @InjectBrowser must receive the same instanceName that you have defined

So your service constructor should be

- 	constructor(@InjectBrowser() private readonly browser: Browser) { }
+ 	constructor(@InjectBrowser('ScrapeInstance') private readonly browser: Browser) { }

I think the problem here is that the error message is quite misleading.

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