Closed szabolcs-szilagyi closed 3 years ago
My first suspicion was that this is a problem with NestJS and not with the integration pattern that's presented in this repository. But, indeed - it is! When running via Nest's own listen
, and not via Next, it works as intended.
Interestingly, yarn build
yields ReferenceError: InjectRepository is not defined
. I suspect a bug in @babel/plugin-proposal-decorators
or babel-plugin-parameter-decorator
. These are the Babel plugins used to transpile decorators.
Got it! From babel-plugin-parameter-decorator
:
By default,
@babel/preset-typescript
will remove imports only referenced in Decorators. Since this is prone to break Decorators, make sure disable it by settingonlyRemoveTypeImports
totrue
.
This is exactly what happens here. LoginTokenRepository
/ InjectRepository
are elided from the bundle, that's why they're "not defined".
I updated this repository's Babel config to implement the suggested fix.
I've read that multiples times, but didn't connect the dots, plus the next/babel
options :sweat_smile:
Thanks for the help @Skn0tt!
I could not figure out sofar what is wrong, but when would like use multiple repositories in a single service one of them turns up undefined.
Eg.: token.service.ts
login-token.repository.ts
the SessionTokenRepository is the same as the login-token one, just different name, table and columns on the db. Don't ask why the two similar token stuff, in the process to rewriting some PHP project with existing db and front-end.
Error:
if I swap the two parameters in the constructor of the service, then it will complain about the other repository not being defined.
Also created a small example to test with TypeORM and MongoDB: https://github.com/Skn0tt/nextjs-nestjs-integration-example/compare/master...szabolcs-szilagyi:test-multi-repository