I'm encountering an issue where the content of my database is not being printed when using an entity with TypeScript/TypeOrm. Here's the code I have:
Main file :
import { createConnection, getManager ,getConnectionOptions } from 'typeorm';
//import {ReleaseController} from "./controller/ReleaseController.js";
//import { attachControllers } from '@decorators/express';
import express from "express";
import { createExpressServer } from 'routing-controllers';
import "reflect-metadata";
import { Release } from "./entity/Release";
const connectionOptions = await getConnectionOptions();
console.log(connectionOptions)
await createConnection(connectionOptions).then(async connection => {
const entityManager = getManager();
let releases = await entityManager.find(Release);
console.log("All releases from the db: ", releases);
}).catch(error => console.log(error));
const app = createExpressServer({
//controllers: [ReleaseController], // we specify controllers we want to use
});
app.listen(3000);
Entity Release :
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
@Entity()
export class Release {
@PrimaryGeneratedColumn()
release_id: number;
@Column({ type: 'date' })
date: string;
@Column()
name: string;
}
TS config :
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"target": "esnext",
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": false,
"allowJs": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
}
},
"include": [ "src/**/*"],
"logging": true,
"logger": "file",
}
Output Error :
node --trace-warnings .
node:internal/process/esm_loader:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/jp/eclipse-workspace/SingleCellSignal/src/entity/Release' imported from /home/jp/eclipse-workspace/SingleCellSignal/src/singlecellsignal.js
at new NodeError (node:internal/errors:363:5)
at finalizeResolution (node:internal/modules/esm/resolve:307:11)
at moduleResolve (node:internal/modules/esm/resolve:742:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
at link (node:internal/modules/esm/module_job:72:36) {
code: 'ERR_MODULE_NOT_FOUND'
}