Search code examples
confignestjstypeorm

typeormconfig in root causes incompatiblity with npm run start:prod script


I have my ormconfig.ts in my project root, my nest app lives in an src folder which seems to be the default after generating a project with the nest cli. However when compiling my dist folder contains my src folder and thus the default npm run start:prod command won't work since it refers to the dist/main folder, not dist/src/main. Now I can fix this in multiple ways but I was wondering if anyone faced this issue before.

dist:

ormconfig.ts
- src
-- modules
-- scripts
-- app.module.ts
-- main.ts

default start:prod command as generated by nest cli: node dist/main


Solution

  • If you want to have the ormconfig be a ts file in the project root, typescript will move js files to dist keeping the same directory structure that you already have. This means that the src directory will be kept because there's a ts file in the root. You can update the start:prod command to point to dist/src/main or you can make ormconfig not be a ts file