question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

schema cli not working when relation

See original GitHub issue

Describe 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:

  1. entity with relation
  2. 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
B4nancommented, Feb 24, 2020

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:

node -r tsconfig-paths/register node_modules/.bin/mikro-orm schema:drop --run

Most probably you could also register in the CLI config programatically:

require('tsconfig-paths').register(); // or this should work too `require('tsconfig-paths/register');`

export default { ... }; // your ORM config

Will take a look if this can be done automatically, for now the above should serve as a workaroud.

0reactions
janacmcommented, Mar 4, 2022

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 running npm install fixed my issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found