typestack / typeorm-typedi-extensions

Dependency injection and service container integration with TypeORM using TypeDI library.
MIT License
262 stars 37 forks source link

question: Error: Cannot get connection "default" from the connection manager. #43

Closed matheusriios closed 3 years ago

matheusriios commented 3 years ago
Error: Cannot get connection "default" from the connection manager. Make sure you have created such connection. Also make sure you have called useContainer(Container) in your application before you established a connection and importing any entity.
    at Object.value (/src/decorators/InjectConnection.ts:12:23)
    at /app/src/ContainerInstance.ts:355:37
    at Array.map (<anonymous>)
    at ContainerInstance.initializeParams (/app/src/ContainerInstance.ts:352:27)
    at ContainerInstance.getServiceValue (/app/src/ContainerInstance.ts:305:47)
    at ContainerInstance.get (/app/src/ContainerInstance.ts:119:21)
    at Object.value (/app/src/decorators/Inject.ts:48:42)
    at /app/src/ContainerInstance.ts:355:37
    at Array.map (<anonymous>)
    at ContainerInstance.initializeParams (/app/src/ContainerInstance.ts:352:27)
[nodemon] app crashed - waiting for file changes before starting...

My index.ts

import 'reflect-metadata';

import { Container } from 'typedi';
import { useContainer } from 'typeorm';
import Application from 'src/Application';

useContainer(Container);

const application = Container.get(Application);

application.start();
stevenhansel commented 3 years ago

Same issue, the error only show up when I'm executing a GraphQL query/mutation from a resolver but there was no error on build/compilation time.

I solved the problem temporarily by changing my TypeORM connection name to default. It seems that useConnection is defaulted to check with the connection name of default.

NoNameProvided commented 3 years ago

The error says it, you attempt to access the connection before you create in TypeORM via calling createConnection. Closing this issue as solved. If your issue still persists please open a new issue with a minimal, reproducible example.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.