0

When executing the command npm run start: dev with migrations configured I receive the error import {MigrationInterface, QueryRunner} from "typeorm"; SyntaxError: Cannot use import statement outside a module

6
  • ormconfig.ts const config: ConnectionOptions = { type: 'mysql', host: process.env.DATABASE_HOST, port: parseInt(process.env.DATABASE_PORT), username: process.env.DATABASE_USER, password: process.env.DATABASE_PASSWORD, database: process.env.DATABASE_NAME, entities: [__dirname + '/**/*.entity{.ts,.js}'], synchronize: false, logging: true, migrationsRun: true, migrations: [__dirname + '/../migrations/**/*{.ts,.js}'], cli: { migrationsDir: './migrations', } } export = config; Commented Oct 23, 2020 at 17:48
  • app.module.ts ConfigModule.forRoot(), TypeOrmModule.forRoot({...ormconfig, keepConnectionAlive: true, autoLoadEntities: true}), Commented Oct 23, 2020 at 17:50
  • package.json "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config ./src/ormconfig.ts", "migration:generate": "npm run typeorm migration:generate -- -n", "migration:run": "npm run typeorm migration:run", "migration:revert": "npm run typeorm migration:revert" Commented Oct 23, 2020 at 17:50
  • migrations work correctly Commented Oct 23, 2020 at 17:52
  • If I remove the migrations files, the command npm run start: dev works fine. Commented Oct 24, 2020 at 3:00

1 Answer 1

0

I fix it by moving the migrations folder inside src.

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

Comments

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.