Search code examples
node.jsnestjstypeormnode.js-typeorm

TypeORM config not reloaded


In the older configuration i'm using mssql as the database,

ormconfig.json:

{
  "type": "mssql",
  "host": "localhost",
  "port": "1433",
  "username": "sa",
  "password": "*******",
  "database": "onboarding",
  "synchronize": true ,
  "logging": true,
  "entities": ["./src/**/*.entity.ts", "./dist/**/*.entity.js"]
}

Then i change the configuration to use postgres

{
  "type": "postgres",
  "host": "localhost",
  "port": "5432",
  "username": "root",
  "password": "*******",
  "database": "onboarding",
  "synchronize": true ,
  "logging": true,
  "entities": ["./src/**/*.entity.ts", "./dist/**/*.entity.js"]
}

Then i uninstalled the mssql driver and add postgres driver through npm, after i restart my program, the TypeOrm keep asking for mssql

[Nest] 40351   - 06/13/2021, 11:01:49 PM   [TypeOrmModule] Unable to connect to the database. Retrying (5)... +3005ms    

DriverPackageNotInstalledError: SQL Server package has not been found installed. Try to install it: npm install mssql --save

Anyone know why the new config not loaded? i've tried npm clean cache, deleting node_modules and dist folder, but still not working.


Solution

  • In case anyone got the same problem as me, it turns out that typeorm ignore the settings on ormconfig.json because i got a variable named TYPEORM_URL on my .env file, any settings related to typeorm on the .env will automatically loaded by type orm and replacing the value from ormconfig.json (i thought we need to parse it manually using process.env).