1

I'm trying to generate a migration with TypeORM by using this command:

npx typeorm migration:generate -n Mock

However, each time that I run this command I get the following error:

Error during migration generation:
/home/raphael-dodobirdai/projects/typeorm-cc/ormconfig.ts:1
import { ConnectionOptions } from "typeorm";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at ConnectionOptionsReader.<anonymous> (/home/raphael-dodobirdai/projects/typeorm-cc/node_modules/typeorm/connection/ConnectionOptionsReader.js:120:46)
    at step (/home/raphael-dodobirdai/projects/typeorm-cc/node_modules/tslib/tslib.js:143:27)
    at Object.next (/home/raphael-dodobirdai/projects/typeorm-cc/node_modules/tslib/tslib.js:124:57)

I have a ormconfig.ts file with the configuration who look like this:

import { ConnectionOptions } from "typeorm";

import { Banker } from './src/entities/Banker';
import { Client } from './src/entities/Client'
import { Transaction } from './src/entities/Transaction'

export const ormconfig: ConnectionOptions = {
  type: 'postgres',
  host: 'localhost',
  port: 5432,
  username: 'xxxxxx',
  password: "yyyyyy",
  database: 'typeorm',
  entities: [Client, Banker, Transaction],
  synchronize: false
}
1

1 Answer 1

-1

You need to run typeorm with ts-node because now it's getting confused about what it should do. Despite TypeORM being a so-called Typescript library, the javascript still peeks through everywhere.

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.