1

while a execute npm run typeorm migration:generate -- -n migrationNameHere all is working good and then when i execute npm run typeorm migration:run all the migration are ok in the database , but when i execute npm run start:dev i get an error :

This is the error i get

the is the tree of my folders:

The structure of my folders

this is my ormconfig.json file:

{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "",
"database": "tpicoxxxxx",
"entities": ["dist/**/*.entity{.ts,.js}"],
"migrationsTableName": "migrations_table",
"migrations": ["src/databasesssx/migrations/*{.ts,.js}"],
"cli": {
    "migrationsDir": "src/databasesssx/migrations"
}

}

in the package.json file i have the following line in scripts section:

 "typeorm": "ts-node-dev ./node_modules/typeorm/cli.js"

i am using typeorm , mysql2

i am using mac big sur.

i thought maybe the problem maybe is because databasesssx folder is outside of src and then i move inside src folder but the problem did not go.

this is my script in registro module:

import { Module } from '@nestjs/common';
 import { TypeOrmModule } from '@nestjs/typeorm';
import { Administrador } from './administrador/entities/administrador.entity';
import { RegistroControllerController } from './registro-controller/registro- 
controller.controller';
import { ServiceRegistroService } from './service-registro/service-registro.service';

 @Module({

  imports : [
    TypeOrmModule.forFeature([Administrador]),
  ],

 providers: [ServiceRegistroService],

  controllers: [RegistroControllerController]  

 })
  export class RegistroModule {}

and this is the script in app.module

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
 import { AppService } from './app.service';
import { RegistroModule } from './registro/registro.module';

   @Module({
  imports: [RegistroModule  ,TypeOrmModule.forRoot()],
   controllers: [AppController],
   providers: [AppService],
   })
   export class AppModule {}

then i tried following the next solution in this site of stack overflow : Similar Problem

but the problem is still there.

By the way i am using xammp in mac with phpmyadmin.

Thank you so much.

4
  • show us your start:dev npm-script Commented Jul 5, 2021 at 2:20
  • what if you change dist to src of your ormconfig Commented Jul 5, 2021 at 2:24
  • Hello @MicaelLevi this is the script: start:dev: nest start --watch is inside package.json. Commented Jul 5, 2021 at 2:24
  • @MicaelLevi if i change dist to src the migrations and all works but the main problem is still there. Commented Jul 5, 2021 at 2:31

1 Answer 1

0

"migrations": ["src/databasesssx/migrations/*{.ts,.js}"],

This tells TypeORM where the migrations exist, which is fine, until you realize that TypeORM will read for the migrations not only at the time of running migrations, but also at time of starting the application. So now, while running nest start --watch which essentially runs node under the hood, the JavaScript engine is importing a Typescript file from src/migrations and is causing an error. If possible, I would separate out the runtime config from the CLI config to ensure this kind of thing cannot happen

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much @Jay McDoniel, well i am going to invesstigate how to do that configuration :). thank you
i dont know how to separate it how can i do it? please
You can make two configuration files, as one option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.