nuxtjs-nestjs-integration
nuxtjs-nestjs-integration copied to clipboard
not work if add some database orm
[Nest] 17392 - 09/22/2021, 3:01:59 PM ERROR [ExceptionsHandler] Cannot read property 'findAll' of undefined TypeError: Cannot read property 'findAll' of undefined
Example https://github.com/Mitch-i/nuxt_nest/tree/main/server
Here is a sample project (not completely finished) that I have that is using ORM with Postgres based on the same idea. https://github.com/davidjamesherzog/devices-client-nuxt
I understand. Is need to use js and not ts file in nuxt as middleware.
import bootstrap from './.nest/nest.js';
Reviving this issue, even with your sample project it cannot build if there's no DB connection
> nest build && nuxt-ts build
[Nest] 64069 - 23.07.2022, 01:37:26 [NestFactory] Starting Nest application...
[Nest] 64069 - 23.07.2022, 01:37:26 [InstanceLoader] AppModule dependencies initialized +131ms
[Nest] 64069 - 23.07.2022, 01:37:26 [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 64069 - 23.07.2022, 01:37:26 [TypeOrmModule] Unable to connect to the database. Retrying (1)... +8ms
error: role "device_api" does not exist
at Parser.parseErrorMessage (devices-client-nuxt/node_modules/pg-protocol/src/parser.ts:357:11)
at Parser.handlePacket (devices-client-nuxt/node_modules/pg-protocol/src/parser.ts:186:21)
at Parser.parse (devices-client-nuxt/node_modules/pg-protocol/src/parser.ts:101:30)
at Socket.<anonymous> (devices-client-nuxt/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (events.js:400:28)
at Socket.emit (domain.js:475:12)
at addChunk (internal/streams/readable.js:293:12)
at readableAddChunk (internal/streams/readable.js:267:9)
at Socket.Readable.push (internal/streams/readable.js:206:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
My assumption is that the handler defined in nuxt.config.js
, e.g. handler: await bootstrap()
is executed during the build step. As a consequence it executes the defined bootstrap function in ./.nest/nest.js
which initializes TypeOrmModule
and attempts to create a connection which fails as there is no DB setup during the build step (https://github.com/davidjamesherzog/devices-client-nuxt/blob/main/server/nest.ts#L5).
Therefore, I think that this approach about using serverMiddleware
with nestjs bootstrap()
might not be suitable. Specially, if we want to run the build command without any DB connection, i.e. docker build
With Nuxt 3 being available for some time now because everyone is moving to Vue 3, I am no longer using this setup and unfortunately, don't have a reason to investigate this further. Sorry.