typeorm: Unable to load entities after update to version 0.3.12

Issue description

After update the typeorm 0.3.11 to version 0.3.12, entities classes cannot be found by path

Expected Behavior

Found all entities classes to load.

All classes found using provided glob pattern "D:\projects\app\src\entities\**\*.entity{.ts,.js}"

Actual Behavior

No entities classes found

No classes were found using the provided glob pattern: "D:\projects\app\src\entities\**\*.entity{.ts,.js}"

Steps to reproduce

Create a new DataSource, configure the DataSource connection, and the entities path.

    const postgresqlDataSource: DataSource = new DataSource({
        type: 'postgres',
        applicationName: 'app,
        host: postgreSQL.host,
        port: postgreSQL.port,
        database: postgreSQL.database,
        username: postgreSQL.username,
        password: postgreSQL.password,
        useUTC: true,
        poolSize: 10,
        connectTimeoutMS: 0,
        dropSchema: false,
        synchronize: false,
        migrationsRun: false,
        uuidExtension: 'uuid-ossp',
        logging: true,
        entities: [join(__dirname, './entities/**/*.entity{.ts,.js}')],
        subscribers: [],
        migrations: [],
    });

My Environment

| Operating System | Windows 10 | | Node.js version | 18.14.0 | | Typescript version | 4.9.5 | | TypeORM version | 0.3.12 |

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don’t know how to start. I would need guidance.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 6
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve encountered this bug as well. I debugged into TypeORM and figured out that it was caused by the update of package glob, which is responsible for resolving the glob pattern used in the entity configuration.
As mentioned in this issue, the update breaks its compatibility on Windows, interpreting “\” as an escape character instead of a valid path separator.
This is the origin of this bug, but another point also contributes to this problem: TypeORM will normalize the path before passing it to glob (util/DirectoryExportedClassesLoader), which will replace all forward slashes with backslashes (because backslash is the primary path separator on Windows). That’s why this bug will still occur even if you use forward slashes in your config file.

Some temporary solutions before a new patch version release:

  • Downgrade to 0.3.11
  • Manually import all entity classes and list them in the config file

This also causes problems with loading migrations. About a soon release of the fix I would be very happy @pleerock ✌️ ☺️

still occurs on 0.3.19

Documentation fix - #10784

0.3.13 fixes the issue for me and all migrations are found again. Thank you 🙏

проблема не только с сущностями но и с миграциями естественно, тоже не ищет