Skip to content

Latest commit

 

History

History
76 lines (44 loc) · 3.66 KB

NestJS-laundry-list.md

File metadata and controls

76 lines (44 loc) · 3.66 KB

My notes on various issues with NestJS and TypeORM that might prevent new developers to get up to the speed.

NestJS - TypeORM shortcomings

  • TypeScript transpiling causes slowdown and all kind of funny errors as seen below. I hope we will have a Node that can directly execute TypeScript without having these issues in the future. See https://www.google.com/search?hl=en&q=%22SyntaxError%3A%20Unexpected%20token%20%7B%22%20nestjs%20migrations

  • No standard way to create PostgreSQL db/tear down db for the tests. No examples or standard way to create database tables for testing.

  • Documentation did not really cover how to use date columns properly. Are they strings? When they are date objects?

  • Documentation does not show good examples of having functions directly on entity classes

  • Reposity concept needs more explanation and examples https://typeorm.io/#/working-with-repository Questions raise: Do I need to write functions manually here? What functions are automatically generated? How does a normal repository look like - links to examples.

  • Repository.create() does not work as advertised typeorm/typeorm#2904

  • NestJS: No idea how HTTP transaction retrying and PostgreSQL transaction conflict on the application level should be wired up - should be the default behavior in the name of safety

  • NestJS and TypeORM docs are not well indexed in Google - first hits point to the Github source

  • NestJS: Some error messages need to be made more helpful and initialisation needs to add checks for the common errors. E.g. I was accidentally providing some service in both app module and its own module, but the error message was misleading.

  • NestKS + TypeORM: The default project generator and structure breaks down when a migration is created nrwl/nx#1393

  • NestJS integration testing framework did not display server side logs - I have no idea why Internal server error is fired in tests

  • Swagger documentation is lacking. E.g. here is the list of methods, but no link or further link to the API documentation: https://docs.nestjs.com/recipes/swagger#decorators

  • TypeORM API docs are very badly formatted and hard to navigate e.g. here https://typeorm.io/#/entity-manager-api

Confusing errors I got

Error 1

Nest] 65019   - 02/14/2020, 3:54:39 PM   [TypeOrmModule] Unable to connect to the database. Retrying (1)... +2785ms
/Users/moo/code/exercise/backend-developer-exercise/src/user/user.entity.ts:1
(function (exports, require, module, __filename, __dirname) { import { Entity, PrimaryGeneratedColumn, Column, Generated, CreateDateColumn, UpdateDateColumn } from 'typeorm';
                                                                     ^

SyntaxError: Unexpected token {

-> Does not make sense, the file is valid TypeScript

This was a bad configuration generated by default project.

The fix was to ensure that TypeORM only scans dist folder JS files. In .env:

TYPEORM_ENTITIES="dist/**/*.entity.js"

Also delete your dist folder if you have leftover files.

Error 2

Error: Nest can't resolve dependencies of the UserService (?). Please make sure that the argument UserRepository at index [0] is available in the AppModule context.

Potential solutions:
- If UserRepository is a provider, is it part of the current AppModule?
- If UserRepository is exported from a separate @Module, is that module imported within AppModule?
  @Module({
    imports: [ /* the Module containing UserRepository */ ]
  })

UserService is in provide section both app.module.ts and user.module.ts. I had to remove it from app.module.ts.