Typeorm Migration:generate failure Not enough non-option arguments: got 0, need at least 1

Viewed 3351

I tried this command in different possible ways but the basic structure of my command was.

 yarn typeorm migration:generate -n=consent-record -d=\"./src/db/CliDataSource.ts\"

this is my typeorm command in the package.json for yarn berry

"typeorm": "ts-node -P ./tsconfig.typeorm.json $(yarn bin typeorm) -d ./src/db/CliDataSource.ts",

I also tried installing typeorm locally as an npm. and also tried with npx. but they all give the following error. "Not enough non-option arguments: got 0, need at least 1" this error clearly doesn't mention what is missing.

my CliDataSource goes like this.

export const CliDataSource = new DataSource({
  type: 'postgres',
  host: 'localhost',
  port: 5436,
  username: '****',
  password: '******',
  database: 'consent',
  synchronize: false,
  logging: false,
  entities,
  migrations,
  migrationsRun: true,
  subscribers: [],
});

enter image description here

I am using typeorm "^0.3.6"

2 Answers

Latest updates to the typeorm has removed -n flag which we used to rename migrations. how it works now is that we need to provide the migration file path. that will store the migration in that specified file. so the updated operations were

my typeorm alias inside package.json.

"typeorm": "ts-node -P ./tsconfig.typeorm.json $(yarn bin typeorm) -d ./src/db/CliDataSource.ts",

CLI Command

 yarn typeorm migration:generate ./src/db/migrations/consent-record

The official documentation seems outdated. hope it will be updated soon.

Special thanks to Jacob Copini @woov

Had the same issue, the workaround I found for now is to use the compiled js file

For example, this will work

npx typeorm migration:generate Init -d dist/db/CliDataSource.js

As the CLI command fails to import the .ts file for some reason, probably because of the file URL it tries to generate, also for some reason it will only import a ts file if the closest package.json file is set to a type => module

File URL ->

typeorm/src/db/CliDataSource.ts


: pathToFileURL(filePath).toString(), 
package.json module type check ->

typeorm/src/db/CliDataSource.ts/

 const isModule = (packageJson as any)?.type === "module" 

This command below does not work

npx typeorm migration:generate Init -d ./src/db/CliDataSource.ts
Related