nestjs-build
nestjs-build copied to clipboard
Add UsersModule with TypeORM
Hey @techvlad,
Thanks a lot for your swc/ESBuild setup. I tried it out but couldn't get it to work with the dependency injection of TypeORM. Do you have any ideas whether this could be resolved? I checked out ESBuild and swc but had no luck finding a solution for it :/
Any hints are appreciated :)
@peterfication - I think your module definition(users.module.ts) might be wrong, shouldn't it be?
@Module({ imports: [TypeOrmModule.forFeature([User])], providers: [UsersService], exports: [UsersService], })
Yeah, right. But it will still fail on another level: QueryFailedError: SQLITE_ERROR: no such table: user1
. (Before it had issues with UserRepository1
)
@peterfication I think this boils down to configuration issues.
the table wont exist unless you create it or make nest generate it
Yes, the table needs to be created, but it shouldn't be called user1
but user
. That's the problem here.
@peterfication - yep, I haven't worked with typeORM so I don't know what the default behaviour is. doesn't seem right indeed :) you could pass in a table name to the entity attribute to go around that though. so there is a workaround at least.
@peterfication - you should be able to retain names and get the table named correctly by modifying the esbuild.transpiler file:
await build({ platform: 'node', target: 'node14', keepNames: true, bundle: false, sourcemap: false, plugins: [await esbuildDecorators({ tsconfig })], entryPoints: [sourceFilePath], outfile: buildFilePath, format: 'cjs', tsconfig, })
See - https://esbuild.github.io/api/#keep-names for more info.
Thanks a lot @gozmanyoni, this fixed it for ESBuild.
Also, SWC added an option called keepClassNames
which will fix it for SWC.
🎉
This resolved it for me 💪