I am currently working on a project using ExpressJS, TypeORM, and TypeScript. However, I have encountered an issue when running the project in develop mode (with app.ts). The first request triggers the following error:
node_modules/src/data-source/DataSource.ts:427
if (!metadata) throw new EntityMetadataNotFoundError(target)
^
EntityMetadataNotFoundError: No metadata for "user" was found.
Strangely, everything works fine when I start the project from /dist/app.js.
I have set es2020 as the target, nodeNext as the module, and specified the moduleResolution in tsconfig. Here is a snippet of my package.json file: `
"type": "module",
"scripts": {
"start": "tsc -p . && node dist/app.js",
"start:prod": "node dist/app.js",
"dev": "ts-node-esm app.ts --watch",
"test": "mocha -r ts-node/register src/**/*.ts",
"test-dev": "nodemon --watch . --ext ts --exec \"mocha -r ts-node/register src/**/*.ts\"",
"build": "rimraf dist && tsc -p .",
}
`
In addition, here is the content of my typeorm.config.ts file:
`
config();
const baseDir = 'dist/src';
export const appDataSource = new DataSource({
type: 'postgres',
host: process.env.POSTGRES_DB_HOST,
port: Number(process.env.POSTGRES_DB_PORT),
username: process.env.POSTGRES_DB_USER,
password: process.env.POSTGRES_DB_PASSWORD,
database: process.env.POSTGRES_DB_DATABASE,
synchronize: false,
logging: true,
entities: [baseDir + '/**/entity/*.entity.js'],
migrationsRun: true,
migrations: [baseDir + '/migrations/*.js'],
});
`
I have attempted to include .ts extensions in the entities and migrations paths but the issue persists.