I'm working in a node.js (+Express) backend and I'm trying to use Mikro-orm without using Typescript.
I followed this project as reference + Mikro-orm documentation but I keep getting this error:
MetadataError: Only abstract entities were discovered, maybe you forgot to use @Entity() decorator?
Is there a way to avoid using Typescript's decorators? Or maybe a better question would be is it possible to use Mikro-orm in a pure JS project?
The configuration file mikro-orm.config.js
looks like:
module.exports = {
entities: [EntityX, EntitiyZ],
type: 'mysql',
dbName: 'example',
highlighter: new SqlHighlighter(),
debug: true
};
The versions I have installed are:
"@mikro-orm/core": "^4.5.10",
"@mikro-orm/mysql": "^4.5.10"
Any help will be much appreciated, thanks!
I was running into this exact problem when I discovered this question (thanks for posting).
I was able to resolve the issue by ensuring the default export from each of my entity files has the shape that Mikro-ORM seems to be expecting, which in your case would look something like:
export default {
EntityX,
schema,
entity: EntityX
}
**EDIT
On second look I realize that you're using CommonJS syntax, so without seeing your entity files I'd assume you could be missing something like:
module.exports.EntityX = EntityX;
module.exports.entity = EntityX;
module.exports.schema = schema;
in your entity file, or you forgot to wire up the entities/index.js
as shown in the example you linked.