schema cli not working when relation
See original GitHub issueDescribe the bug When i use schema cli without relation. it works as expect. But when i used schmea cli using entity with relation for other entity, error ocurred with following stack trace. I assume that typesciprt paths occur error.
Stack trace
> api@1.0.0 schema:drop:dev /Users/seunggu/Desktop/api
> mikro-orm schema:drop --run
Error: Cannot find module '@shared/infra/persistence/repoitory/test/entity/Test.entity'
Require stack:
- /Users/seunggu/Desktop/api/src/shared/infra/persistence/repoitory/test/entity/TestValueObject.entity.ts
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/metadata/MetadataDiscovery.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/metadata/index.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/utils/Configuration.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/utils/index.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/EntityManager.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/MikroORM.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/cli/CLIHelper.js
- /Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/seunggu/Desktop/api/src/shared/infra/persistence/repoitory/test/entity/TestValueObject.entity.ts:4:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Module.m._compile (/Users/seunggu/Desktop/api/node_modules/ts-node/src/index.ts:814:23)
at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Object.require.extensions.<computed> [as .ts] (/Users/seunggu/Desktop/api/node_modules/ts-node/src/index.ts:817:12)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at MetadataDiscovery.getEntityClassOrSchema (/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/metadata/MetadataDiscovery.js:414:25)
at MetadataDiscovery.discoverDirectory (/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/metadata/MetadataDiscovery.js:80:33)
at Function.runSerial (/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/utils/Utils.js:303:22) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/seunggu/Desktop/api/src/shared/infra/persistence/repoitory/test/entity/TestValueObject.entity.ts',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/metadata/MetadataDiscovery.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/metadata/index.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/utils/Configuration.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/utils/index.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/EntityManager.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/MikroORM.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/cli/CLIHelper.js',
'/Users/seunggu/Desktop/api/node_modules/mikro-orm/dist/cli.js'
]
}
To Reproduce Steps to reproduce the behavior:
- entity with relation
- cli for schema drop or create
Expected behavior cli works as expect
Additional context
Versions 3.2.1
Dependency | Version |
---|---|
node | 12.14.0 |
typescript | 3.7.5 |
mikro-orm | 3.2.1 |
your-driver | mysql2 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why command \dt gives - no relations found? - Stack Overflow
Use \dt . * to list all tables with name matching in all schemas. Assuming the table exists, it will tell you what...
Read more >Troubleshooting relations - Prisma
The back relation fields are missing from the Post to PostCategories and Category to PostCategories models. // This example schema shows how NOT...
Read more >postgresql - \dt says "Did not find any relations."
From the question, I suspect that the abc database had all of its tables created in the default public schema, while the xyz...
Read more >Command Line Interface (CLI) — CKAN 2.9.7 documentation
If you have trouble running 'ckan' CLI commands, see Troubleshooting ckan Commands below. ... You will not be required to use –config or...
Read more >Documentation: 15: 5.9. Schemas - PostgreSQL
A PostgreSQL database cluster contains one or more named databases. ... Unlike databases, schemas are not rigidly separated: a user can access objects...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is not about relations, but rather about you using custom paths mapping. When you run the app normally, some framework you are probably using is registering
tsconfig-paths
so your custom mapping can work. That is obviously not done when you run MikroORM CLI, so you need to register them manually.https://github.com/dividab/tsconfig-paths
Not very ergonomic, but something like this should work:
Most probably you could also register in the CLI config programatically:
Will take a look if this can be done automatically, for now the above should serve as a workaroud.
Note to self: This happened when I copy-pasted a repo that uses MikroORM, including its
node_modules
folder. Deleting the node modules folder and runningnpm install
fixed my issue.