Reputation: 27
i'm trying to build a backend with nodejs & express & typeorm using typescript.
I have a problem that when i run application with nodemon
it's work like intended. But when i start with node app.js
on compiled javascript files and send request to any end point it's givin me the error EntityMetadataNotFoundError
. How can i get pass this issue ?
ormconfig.json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "",
"password": "",
"database": "",
"entities": [
"dist/src/entity/**/*.js",
"src/entity/**/*.ts"
],
"migrations": [
"dist/src/migration/**/*.js",
"src/migration/**/*.ts"
],
"subscribers": [
"dist/src/subscriber/**/*.js",
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "dist/src/entity",
"migrationsDir": "dist/src/migration",
"subscribersDir": "dist/src/subscriber"
}
}
i don't know if needed but here is tsconfig.json
{
"compilerOptions": {
"lib": [
"es5",
"es6",
"es7",
"es2015",
"es2016",
"es2017",
"es2018",
"esnext"
],
"target": "es5",
"module": "commonjs",
"moduleResolution": "Node",
"outDir": "dist",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
my build script is tsc --project .
Any help is appreciated, thank you.
Upvotes: 0
Views: 886
Reputation: 3472
I was running in to the same issue with typeorm:"0.35", which doesn't use ormconfig.json anymore.
In my case the solution was to add the path to the entities in the build folder, such as this "entities: ["build/entity/*.js"]" instead of the development path "entities: ["src/entity/*.ts"]" Note the js vs ts, and the build vs src.
Upvotes: 1
Reputation: 27
Okay,i figured out. tsc --project .
command not copying the ormconfig.json
file to dist
directory. I changed tsconfig.json
and it works now!
I added include
and resolveJsonModule
properties.
tsconfig.json
{
"compilerOptions": {
"lib": [
"es5",
"es6",
"es7",
"es2015",
"es2016",
"es2017",
"es2018",
"esnext"
],
"target": "es5",
"module": "commonjs",
"moduleResolution": "Node",
"resolveJsonModule": true,
"outDir": "dist",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": [
"ormconfig.json"
]
}
Upvotes: 0