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

Nest can't resolve dependencies of the AlgoliaService (?). Please make sure that the argument at index [0] is available in the context. #1

Open
p-salmon opened this issue Sep 24, 2019 · 3 comments
Assignees

Comments

@p-salmon
Copy link

p-salmon commented Sep 24, 2019

Error message

2019-09-24T18:02:00.115Z [ERROR] [ExceptionHandler]     Nest can't resolve dependencies of the AlgoliaService (?). Please make sure that the argument at index [0] is available in the SearchIndexModule context.Error: Nest can't resolve dependencies of the AlgoliaService (?). Please make sure that the argument at index [0] is available in the SearchIndexModule context.
    at Injector.lookupComponentInExports (/Users/paulsalmon/workspace/plato/plato-monorepo-research/node_modules/@nestjs/core/injector/injector.js:183:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
    at Object.<anonymous> (/Users/paulsalmon/workspace/plato/plato-monorepo-research/node_modules/ts-node/src/bin.ts:158:12)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
error Command failed with exit code 1.
// search-index.module.ts
import { Module } from '@nestjs/common';
import { AlgoliaModule, AlgoliaService } from 'nestjs-algolia';
import { SearchIndexService } from './search-index.service';

@Module({
  imports: [
    AlgoliaModule.register({
      applicationId: 'APPLICATION_ID',
      apiKey: 'API_KEY',
    }),
  ],
  providers: [AlgoliaService, SearchIndexService],
})
export class SearchIndexModule {}
// search-index.service.ts
import { Injectable } from '@nestjs/common';
import { AlgoliaService } from 'nestjs-algolia';

@Injectable()
export class SearchIndexService {
  constructor(private readonly algoliaService: AlgoliaService) {}
}

Versions:
@nestjs/common - 6.7.1
@nestjs/core - 6.7.1
nestjs-algolia - 1.1.0

Hello! Thank you for the project. So I am having this error that I would guess is related to the last update of Nest. Any idea?

@fvilers fvilers self-assigned this Sep 26, 2019
@fvilers
Copy link
Owner

fvilers commented Sep 26, 2019

Hi Paul,

I've prepared an update to the library to support nestjs 6. As I don't have the time to migrate one of my application yet, can I ask you to test if the changes I've made are working for you?

Here's how you can proceed:

  • checkout the v2 branch to a temporary directory
cd ~/temp
git clone https://github.com/fvilers/nestjs-algolia.git
cd nestjs-algolia
git checkout v2.0.0
  • build the v2:
npm install
npm run build
  • make this build available locally:
cd dist
npm link
  • use it in your project
cd ~/your-project
npm uninstall nestjs-algolia
npm link nestjs-algolia

If everything works great, I'll publish the package on npm and you will be able to use it from there.

  • remove local link:
cd ~/your-project
npm unlink nestjs-algolia
cd ~/temp/nestjs-algolia/dist
npm unlink

@p-salmon
Copy link
Author

Hi,

Thank you very much for the fix and sorry for the delay.

We are getting this error:

Nest can't resolve dependencies of the AlgoliaService (?). Please make sure that the argument ALGOLIA_MODULE_OPTIONS at index [0] is available in the SearchIndexModule context.

Potential solutions:
- If ALGOLIA_MODULE_OPTIONS is a provider, is it part of the current SearchIndexModule?
- If ALGOLIA_MODULE_OPTIONS is exported from a separate @Module, is that module imported within SearchIndexModule?
  @Module({
    imports: [ /* the Module containing ALGOLIA_MODULE_OPTIONS */ ]
  })
Error: Nest can't resolve dependencies of the AlgoliaService (?). Please make sure that the argument ALGOLIA_MODULE_OPTIONS at index [0] is available in the SearchIndexModule context.

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

    at Injector.lookupComponentInExports (/Users/paulsalmon/workspace/plato/plato-monorepo-research/node_modules/@nestjs/core/injector/injector.js:183:19)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:56:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:880:11)
    at Object.<anonymous> (/Users/paulsalmon/workspace/plato/plato-monorepo-research/node_modules/ts-node/src/bin.ts:158:12)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
error Command failed with exit code 1.

The fix for this is to export the ALGOLIA_MODULE_OPTIONS in the algolia.module.ts, then it's working perfectly:

@Module({
  providers: [AlgoliaService],
  exports: [ALGOLIA_MODULE_OPTIONS, AlgoliaService],
})

Are you happy with this change? If so I can cook a PR on your v2 version.

Thanks again!

@fvilers
Copy link
Owner

fvilers commented Oct 28, 2019

Hi, sorry for the late response. I added the ALGOLIA_MODULE_OPTIONS to the export array. Could you give a try again?

Thanks in advance!

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