FG
💻 Software🗄️ Databases

Typeorm CLI not works perfectly after 0.3.0

Fresh5 days ago
Mar 14, 20260 views
Confidence Score69%
69%

Problem

Issue Description After version 0.3.0 cli does not work perfectly. when I try to create an entity or migration using cli is create entity or migration in the root directory. However, in the old version, it works perfectly. It shows this error with the new version 0.3.0 [code block] Expected Behavior while when I use 0.2.17 version. it works with same command. [code block]

Error Output

error with the new version 0.3.0

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix TypeORM CLI Directory Issue in Version 0.3.0

Medium Risk

In TypeORM version 0.3.0, the CLI behavior was changed, causing migrations and entities to be created in the root directory instead of the specified directories. This is likely due to changes in the default configuration settings or the way paths are resolved in the new version.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update TypeORM Configuration

    Ensure that your TypeORM configuration file (ormconfig.json or equivalent) specifies the correct paths for entities and migrations. This will guide the CLI to create files in the intended directories.

    json
    {
      "type": "postgres",
      "host": "localhost",
      "port": 5432,
      "username": "test",
      "password": "test",
      "database": "test",
      "entities": ["src/entity/**/*.ts"],
      "migrations": ["src/migration/**/*.ts"],
      "cli": {
        "entitiesDir": "src/entity",
        "migrationsDir": "src/migration"
      }
    }
  2. 2

    Check CLI Command Syntax

    Verify that you are using the correct syntax for the TypeORM CLI commands. The command should specify the correct paths if not using the default configuration.

    bash
    typeorm migration:create -n MigrationName --dir src/migration
  3. 3

    Clear Cache

    Sometimes, TypeORM may cache configurations. Clear any existing cache to ensure the new settings are applied. You can do this by deleting the 'node_modules/.cache' directory if it exists.

    bash
    rm -rf node_modules/.cache
  4. 4

    Reinstall TypeORM

    If the issue persists, try reinstalling TypeORM to ensure that all files are correctly set up. This can resolve any inconsistencies that may have arisen during the upgrade.

    bash
    npm uninstall typeorm && npm install typeorm
  5. 5

    Test CLI Functionality

    After making the above changes, test the CLI commands again to confirm that entities and migrations are created in the correct directories.

    bash
    typeorm entity:create -n TestEntity

Validation

Confirm that the entities and migrations are created in the specified directories (e.g., src/entity and src/migration) instead of the root directory. Check for any errors during the creation process.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typeormormtypescriptquestionstale