Encountered a glitch while compiling Nestjs using typeorm

I encountered an issue when attempting to include the entity.ts in the project

Here is the content of ts file:

import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"


@Entity('Usuario')
export class UsuarioIdentity {
    @PrimaryGeneratedColumn() id: number;

    @Column('text') username: string;

    @Column('text') password: string;
}

This is my ormconfig:

{
    "type": "mysql",
    "host": "localhost",
    "port": "3306",
    "username": "root",
    "password": "password",
    "database": "blogdb",
    "synchronize": true,
    "logging": true,
    "entities": ["src/Entidades/*.entity{.ts,.js}", "dist/Entidades/*.entity{.ts,.js}"]
}

The Error message displayed is as follows:

[Nest] 21736   - 2021-06-03 3:04:09 PM   [NestFactory] Starting Nest application...
[Nest] 21736   - 2021-06-03 3:04:09 PM   [InstanceLoader] TypeOrmModule dependencies initialized >+148ms
[Nest] 21736   - 2021-06-03 3:04:09 PM   [InstanceLoader] AppModule dependencies initialized +2ms
[Nest] 21736   - 2021-06-03 3:04:09 PM   [TypeOrmModule] Unable to connect to the database. 
Retrying (1)... +21ms
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
   ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:721:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at E:\Proyectos_ejemplos\React- 
NestJS\Back2\node_modules\typeorm\util\DirectoryExportedClassesLoader.js:42:39
    at Array.map (<anonymous>)
    at Object.importClassesFromDirectories (E:\Proyectos_ejemplos\React- 
NestJS\Back2\node_modules\typeorm\util\DirectoryExportedClassesLoader.js:42:10)

If I comment out the entity or delete it, everything seems to work fine. I am currently using NestJS version 7.6.15 and typeorm version 0.2.34

Please provide assistance if possible :D

UPDATE

Below is my tsconfig file where I suspect the issue might be related to the outDir setting

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}

Answer №1

Consider updating the entities section in your ORM configuration file like this:

"entities": ["src/Entities/*.entity{.ts,.js}"]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on deactivating the div in angular using ngClass based on a boolean value

displayData = [ { status: 'CLOSED', ack: false }, { status: 'ESCALATED', ack: false }, { status: 'ACK', ack: false }, { status: 'ACK', ack: true }, { status: 'NEW', ack ...

Do I have to use a prepared statement when executing a SELECT query?

When you receive user input, such as an email address, and use htmlspecialchars() like this: $email = htmlspecialchars($_POST['email']); Do you need to use a prepared statement for a SELECT query? ...

The recommended filename in Playwright within a Docker environment is incorrectly configured and automatically defaults to "download."

Trying to use Playwright to download a file and set the filename using download.suggestedFilename(). Code snippet: const downloadPromise = page.waitForEvent('download', {timeout:100000}) await page.keyboard.down('Shift') await p ...

Encountered an issue while importing data from a MySQL backup file

When using the mysqldump npm module to import a backfile, I encountered the following error: var mysqlDump = require('mysqldump'); mysqlDump({ host: 'localhost', user: 'root', password: '', database ...

Can you identify a specific portion within an array?

Apologies for the poorly titled post; summarizing my query into one sentence was challenging. I'm including the current code I have, as I believe it should be easy to understand. // Constants that define columns const columns = ["a", " ...

Challenges with counting in MySQL

SELECT count( t1.id ) , t2.special_value FROM table_1 AS t1, table_2 AS t2 WHERE t1.`group` = 'val' AND t2.code = 'val' delivers count - regular value special_value - NULL whereas SELECT t2.special_value FROM table_2 AS t2 WHERE t2 ...

Tips on maintaining the chosen product while navigating to a different component

I have a dilemma with 2 different components that are responsible for creating an invoice. The first component adds more products The second component adds invoice details Initially, I enter the invoice details and select the client's name. The sel ...

Using PHP to create an HTTP download stream from a MySQL database

Can someone provide guidance on reading data from MySQL and then writing it to an HTTP output stream? For example, if I send a request to , I would like to retrieve the corresponding data for "A" from MySQL using PHP. The data is in plain text format. T ...

Using foreign key attribute in a Tastypie detail URI

I've customized the User Django class by creating my own user class in Django: class MyUser(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, related_name='my_user') theme = models.Intege ...

Ways to assign a unique number to every row retrieved from mysql in real-time

My goal is to automatically assign a unique number to each row returned from a MySQL table and then echo that number. I don't want to just count rows, I want to give each one a specific identifier. I apologize for any outdated code in advance. $log ...

Encountering a TypeScript error in Next.js: The 'Options' type does not align with the 'NavigateOptions' type

My code snippet: import { useRouter } from 'next/navigation'; interface Options { scroll: boolean; } const Component = () => { const router = useRouter(); const updateSearchParams = () => { const searchParams = new URLSearchPa ...

Developing a personalized validation function using Typescript for the expressValidator class - parameter is assumed to have a type of 'any'

I'm seeking to develop a unique validation function for express-validator in typescript by extending the 'body' object. After reviewing the helpful resource page, I came across this code snippet: import { ExpressValidator } from 'expre ...

Importing PHP backend variables into ReactJS with the help of webpack

Is there a way to pass a PHP backend variable into my ReactJS (using react-router) application via Webpack? I'm interested in accomplishing something like this: <?php if ($us->inGroup('Admin')) { ?> <script> var ...

Aurelia's navigation feature adds "?id=5" to the URL instead of "/5"

I have set up my Aurelia Router in app.ts using the configureRouter function like this: configureRouter(config, router: Router) { config.map([ { route: ['users', 'users/:userId?'], na ...

Example of Signature in TypeScript Function Declaration

While going through this documentation, I found myself puzzled by the concept of having a parameter that can be both an object and a function in JavaScript. type DescribableFunction = { description: string; (a: any): boolean; }; function doSomething( ...

SQL database error: There is an unidentified character present in the column

One of the columns appears to have a unique character in front of the data. My query results no results when executed as follows: SELECT * FROM `stocktake_products` WHERE `stocktake_id` = 4148 AND `stocktake_product_id` = '29153796' However, r ...

What are some ways to create a dynamic child server component?

Take a look at the following code snippet // layout.tsx export default function Layout({children}: any) { return <div> {children} </div> } // page.tsx export const dynamic = "force-dynamic"; const DynamicChild = dynamic( ...

What is the best way to update rows in a table with values separated by commas?

There are two tables, the first table contains names, email addresses, favorite vegetables and fruits, and preferred drinks. CREATE TABLE Likes ( Name varchar(20), email varchar(20), Vegetables_Fruits varchar(20), Drinks varchar(20) ) I am storing the na ...

Grunt Typescript is encountering difficulty locating the angular core module

Question Why is my Grunt Typescript compiler unable to locate the angular core? I suspect it's due to the paths, causing the compiler to not find the libraries in the node_modules directory. Error typescript/add.component.ts(1,25): error TS23 ...

Updating the Angular2 function in the main app component causes the current component to be reset

I developed an application that has the following structure: app.component.ts import { Component } from 'angular2/core'; import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; import { NgClass } from &apos ...