-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[webpack start:hmr] SyntaxError: Unexpected token import on TypeORM entity files #1018
Comments
I was able to fix this issue by configuring TypeORM inside my app's root module (instead of using a Is this the correct way / is there some other better solution? Thanks. My root module now: import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { RecordsModule } from './records/records.module';
import { Record } from './records/record.entity';
@Module({
imports: [
TypeOrmModule.forRoot({
keepConnectionAlive: true,
type: 'postgres',
host: 'localhost',
port: 5432,
username: '***',
password: '***',
database: '***',
synchronize: true, // TODO: Remove in production!
entities: [ // Passing entities as class references so that webpack doesn't break
Record
],
migrations: [__dirname + '/migration/**/*.ts'],
subscribers: [__dirname + '/subscriber/**/*.ts'],
}),
RecordsModule,
],
controllers: [
AppController,
],
providers: [
AppService,
],
})
export class AppModule {} |
try change |
@whtiehack thanks but it was already set to |
The entities are loaded on the fly by the TypeOrm, and therefore, webpack doesn't that these paths should be treated differently than just plain literal strings. Your solution is the best available one so far. |
Maybe a better workaround: Write a loader like this and pass |
another option would be to create the app.module.ts import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import ormconfig from 'orm.config';
@Module({
imports: [
TypeOrmModule.forRoot(ormconfig),
]
})
export class AppModule {} File orm.config.ts import { EntityOne } from './entityone.entity';
import { EntityTwo } from './entitytwo.entity';
let ormconfig = {
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "your_user",
"password": "**********",
"database": "your_database",
"entities": [EntityOne, EntityTwo], //<----include all
"synchronize": true
};
export default ormconfig; |
Hi Guys, I'm able to fix this issue by changing configuration in nodemon.json as below.
|
Is there a reason why |
thanks, worked for me |
Hi, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Current behavior
When running
npm run start:hmr
(note thatnpm run webpack
is running) on a project created with the CLI and containing a TypeORM entity file, I get the following error:Expected behavior
I would expect no errors. It seems like the entity file does not get compiled to JavaScript.
Minimal reproduction of the problem with instructions
npm run webpack
npm run start:hmr
What is the motivation / use case for changing the behavior?
Environment
I am new to Nest so please excuse me If I am making a stupid mistake.
I was not able to find details in the documentation about hot reloading on a CLI project. Thanks!
The text was updated successfully, but these errors were encountered: