RobinCK / typeorm-fixtures

:pill: Fixtures loader for typeorm 🇺🇦
https://robinck.github.io/typeorm-fixtures/
MIT License
563 stars 45 forks source link

Cannot execute operation on "default" connection because connection is not yet established #72

Open marciobarroso opened 5 years ago

marciobarroso commented 5 years ago

I have a makefile with a command:

db-sync: NODE_ENV=$(NODE_ENV) $(NPM_BIN)/fixtures --config ./ormconfig.js --sync --debug ./data/fixtures

When I run this code, I get: Fail fixture loading: Unexpected token { (node:53075) UnhandledPromiseRejectionWarning: CannotExecuteNotConnectedError: Cannot execute operation on "default" connection because connection is not yet established. at new CannotExecuteNotConnectedError (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/typeorm/error/CannotExecuteNotConnectedError.js:10:28) at Connection.<anonymous> (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/typeorm/connection/Connection.js:173:35) at step (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/tslib/tslib.js:136:27) at Object.next (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/tslib/tslib.js:117:57) at /Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/tslib/tslib.js:110:75 at new Promise (<anonymous>) at Object.__awaiter (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/tslib/tslib.js:106:16) at Connection.close (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/typeorm/connection/Connection.js:168:24) at Object.<anonymous> (/Users/marcio/Development/projects/personal/typescript-express-di-orm/node_modules/typeorm-fixtures-cli/dist/cli.js:111:37) at Generator.next (<anonymous>) (node:53075) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:53075) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Fun fact: I use the same configuration to run fixtures before my unit-tests programmatically and works well

ormconfig.js { "name":"default", "type":"mysql", "host":"127.0.0.1", "port":3306, "username":"blablabla", "password":"blablabla", "database":"blablabla", "ssl":false, "entityPrefix":"", "synchronize":true, "dropSchema":true, "logging":[ "query", "error", "schema", "warn", "info", "log" ], "extra":{ "ssl":false }, "autoSchemaSync":true, "entities":[ "./src/entities/*.*" ], "migrations":[ "./src/migrations/*.*" ], "subscribers":[ "./src/subscribers/*.*" ], "cli":{ "entitiesDir":"./src/entities", "migrationsDir":"./src/migrations", "subscribersDir":"./src/subscribers" } }

Do you guys have any idea what could be wrong? For me, this seems the fixture is trying to run before have a opened connection. But make no sense because all logic is inside the then of createConnection

mtbvang commented 4 years ago

When I add --require=ts-node/register to the fixture command this error changes to

{ RepositoryNotFoundError: No repository for "User" was found. Looks like this entity is not registered ? at new RepositoryNotFoundError (/app/cs-backend/src/error/RepositoryNotFoundError.ts:10:9) at EntityManager.getRepository (/app/cs-backend/src/entity-manager/EntityManager.ts:1008:19) at Connection.getRepository (/app/cs-backend/src/connection/Connection.ts:341:29) at Builder.<anonymous> (/app/cs-backend/node_modules/typeorm-fixtures-cli/src/Builder.ts:18:44) at Generator.next (<anonymous>) at /app/cs-backend/node_modules/typeorm-fixtures-cli/dist/Builder.js:7:71 at new Promise (<anonymous>) at __awaiter (/app/cs-backend/node_modules/typeorm-fixtures-cli/dist/Builder.js:3:12) at Builder.build (/app/cs-backend/node_modules/typeorm-fixtures-cli/dist/Builder.js:26:16) at Object.<anonymous> (/app/cs-backend/node_modules/typeorm-fixtures-cli/src/cli.ts:108:47) name: 'RepositoryNotFoundError', message: 'No repository for "User" was found. Looks like this entity is not registered in current "default" co}

I don't know if this is actually progress or not or if it's just a different error.

SeverinAlexB commented 4 years ago

I had the same CannotExecuteNotConnectedError error. Adding --require=ts-node/register made the real error show up.

I can only recommend everybody to add --require=ts-node/register at the command.

peresbruno commented 4 years ago

Hi @mtbvang! Have you solved your issue related to RepositoryNotFoundError? I have the same issue here.

fsodano commented 3 years ago

late to the party but if you have a .env, the config files get ignored and .env is used instead.