Closed heldercunha closed 1 year ago
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:
Thanks @truemogician for investigation and detailed explanation.
проблема не только с сущностями но и с миграциями естественно, тоже не ищет
This also causes problems with loading migrations. About a soon release of the fix I would be very happy @pleerock :v: :relaxed:
Esto también se convierte en un problema si contamos con distintos ambientes (develop, stage, preprod, production), nos obliga a tener un archivo de migración por cada ambiente, si seria bueno una solución para esto
Is that feature not anyway deprecated or did i read wrong in the past changelogs?
0.3.13 fixes the issue for me and all migrations are found again. Thank you 🙏
Is that feature not anyway deprecated or did i read wrong in the past changelogs?
Yes, it is deprecated and not recommended to be used anymore. From the changelog:
DEPRECATIONS
entities
, migrations
, subscribers
options inside DataSourceOptions accepting string
directories support is deprecated. You'll be only able to pass entity references in the future versions.Which means, as I understand it, that from version 0.3.0 we need to list real entities in the array of entities and not a list of string paths to files:
import { MyEntity1 } from '@/path/to/MyEntity1'
import { MyEntity2 } from '@/path/to/MyEntity2'
new DataSource({
entities: [MyEntity1, MyEntity2]
})
still occurs on 0.3.19
Same here on 0.3.20
@eder-abbvie, @Mnigos
And it will be for all the eternity. As mentioned above, the feature of providing entities be file paths is deprecated. All entities are now needed to be imported and added to an array explicitly.
@Kolobamanacas
So now the only way to load entities is to manually import them and insert into array like this?
import { User } from '@modules/users'
import { Artist } from '@modules/artists'
export const typeOrmConfig: TypeOrmModuleOptions = {
entities: [User, Artist],
}
If yes, please update the documentation, because this is quite confusing.
And how about migrations? Do we need to import them manually too?
Documentation fix - #10784
So now the only way to load entities is to manually import them and insert into array like this? And how about migrations? Do we need to import them manually too?
Yes and yes. :)
Btw, I'm not maintainer yet, I've just faced the same issue during the update.
Do not use the letter i as the beginning of the file name.
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.
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)
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.