atls / nestjs

NestJS Custom Workshop
BSD 3-Clause "New" or "Revised" License
33 stars 8 forks source link

Connection isn't provided #219

Closed TFK70 closed 2 years ago

TFK70 commented 3 years ago

Описание бага

  1. @atls/nestjs-typesense-typeorm
  2. Инициализация модуля

Воспроизведение

Шаги для воспроизведения бага:

  1. Инициализируем окружение (nest, typesense, typeorm)
  2. Инициализируем модули
  3. Видим ошибку, проект не билдится

Ожидаемое поведение

Моудль инициализируется без ошибок

Материалы

[Nest] 9690  - 10/17/2021, 2:36:58 PM     LOG [InstanceLoader] TypeOrmModule dependencies initialized +53ms
[Nest] 9690  - 10/17/2021, 2:36:58 PM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the TypeOrmListenersBuilder (TypesenseMetadataRegistry, EntityToDocumentMapper, ?). Please make sure that the argument Connection at index [2] is available in the TypesenseTypeOrmModule context.

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

Error: Nest can't resolve dependencies of the TypeOrmListenersBuilder (TypesenseMetadataRegistry, EntityToDocumentMapper, ?). Please make sure that the argument Connection at index [2] is available in the TypesenseTypeOrmModule context.

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

    at Injector.lookupComponentInParentModules (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/injector.js:201:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at Injector.resolveComponentInstance (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/injector.js:156:33)
    at resolveParam (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/injector.js:108:38)
    at async Promise.all (index 2)
    at Injector.resolveConstructorParams (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/injector.js:123:27)
    at Injector.loadInstance (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/injector.js:52:9)
    at Injector.loadProvider (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/injector.js:74:9)
    at async Promise.all (index 4)
    at InstanceLoader.createInstancesOfProviders (/home/dozer/workspace/typesense-demo/.yarn/unplugged/@nestjs-core-virtual-d5967d0c39/node_modules/@nestjs/core/injector/instance-loader.js:44:9)

Репа с репродьюсом

https://github.com/TFK70/typesense-demo/pull/2

  1. docker-compose up db
  2. docker-compose up typesense
  3. export TYPESENSE_API_KEY=testkey (из-под докера пока не работает)
  4. yarn dev

Данные окружения

TorinAsakura commented 3 years ago

‘yarn why typeorm’ - typeorm хранит connections глобально внутри пакета, т.е у тебя подключаются несколько пакетов, в одном connection создаётся, а где ты его пытаешься подключить это другой пакет, там пусто - т.е нужно резолвить зависимости