Nico
Nico

Reputation: 1

Nestjs/typeorm error after upgrade to 8.x Unable to connect

After upgrading from nestjs 7.x to nestjs 8 I get an typeorm error:

ERROR [TypeOrmModule] Unable to connect to the database.
2022-01-07T19:31:13.955332+00:00: TypeORMError: Entity metadata for c#mymodel was not found. Check if you specified a correct entity object and if it's connected in the connection options.
2022-01-07T19:31:13.955333+00:00: at new TypeORMError (/app/node_modules/typeorm/error/TypeORMError.js:9:28)
2022-01-07T19:31:13.955336+00:00: at /app/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:597:23
2022-01-07T19:31:13.955337+00:00: at Array.forEach (<anonymous>)
2022-01-07T19:31:13.955338+00:00: at EntityMetadataBuilder.computeInverseProperties (/app/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:593:34)
2022-01-07T19:31:13.955338+00:00: at /app/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:85:74
2022-01-07T19:31:13.955338+00:00: at Array.forEach (<anonymous>)
2022-01-07T19:31:13.955339+00:00: at EntityMetadataBuilder.build (/app/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:85:25)
2022-01-07T19:31:13.955339+00:00: at ConnectionMetadataBuilder.buildEntityMetadatas (/app/node_modules/typeorm/connection/ConnectionMetadataBuilder.js:57:148)
2022-01-07T19:31:13.955340+00:00: at Connection.buildMetadatas (/app/node_modules/typeorm/connection/Connection.js:513:57)
2022-01-07T19:31:13.955340+00:00: at Connection.<anonymous> (/app/node_modules/typeorm/connection/Connection.js:126:30)

This happens only in both of my heroku instances. My local instance works fine!

I changed nothing in my entities or other stuff besides the upgrade. I also tested a script on the server with same credentials and it connected as expected.

So my question: What changes in the upgrade could cause the error? It seems strange that the error says "Unable to connect to the database", but the error causing that seems to be thrown in EntityMetadataBuilder.computeInverseProperties and does not say anything like "host not reachable" or "SSL error" or anything which is typical for a connection failure so maybe the error is misleading?

If I look in the source code I see the error saying: "Entity metadata for " + entityMetadata.name + "#" + relation.propertyPath + " was not found" The error output is: Entity metadata for c#mymodel was not found I have a propertyPath "mymodel" but no entityMetadata.name "c" ?

If I switch back to the previous version it works again. The database is postgres.

Addendum: I just realized that the bootstrap process shows some strange shortened module names consisting of single characters or underscore. Any ideas what could cause that?:

[Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] _ dependencies initialized +13ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] MailerCoreModule dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] a dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] WinstonModule dependencies initialized +2ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] ServeStaticModule dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] ServeStaticModule dependencies initialized +0ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] _ dependencies initialized +0ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] a dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] l dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] l dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] u dependencies initialized +1ms
app[web.1]: [Nest] 4  - 01/17/2022, 9:00:20 PM     LOG [InstanceLoader] _ dependencies initialized +2ms

Upvotes: 0

Views: 702

Answers (1)

Nico
Nico

Reputation: 1

So it seems the reason for the failure is a change in webpack configuration of nx. If the optimization flag for webpack is true all class names will be minified.

As assumed the error message saying "Unable to connect..." is completely misleading. The problem is not database related.

There is an issue on github/nrwl

Upvotes: 0

Related Questions