question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[webpack start:hmr] SyntaxError: Unexpected token import on TypeORM entity files

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When running npm run start:hmr (note that npm run webpack is running) on a project created with the CLI and containing a TypeORM entity file, I get the following error:

[Nest] 10906   - 2018-8-29 16:41:14   [TypeOrmModule] Unable to connect to the database. Retrying (6)... +3011ms
/mnt/c/********/src/records/record.entity.ts:1
(function (exports, require, module, __filename, __dirname) { import { Entity, Column, PrimaryGeneratedColumn, VersionColumn, CreateDateColumn,
UpdateDateColumn } from 'typeorm';
                                                              ^^^^^^

SyntaxError: Unexpected token import

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

  1. Create a new project with the Nest CLI
  2. Add TypeORM to the project
  3. Create a TypeORM entity file
  4. Run npm run webpack
  5. On another terminal run npm run start:hmr
  6. Observe the error

What is the motivation / use case for changing the behavior?

Environment


[System Information]
OS Version     : Linux 4.4
NodeJS Version : v8.11.4
NPM Version    : 6.4.0
[Nest Information]
typeorm version : 5.2.0
common version  : 5.0.0
core version    : 5.0.0

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!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
JayAhn2commented, Jun 18, 2019

Hi Guys,

I’m able to fix this issue by changing configuration in nodemon.json as below.

nodemon.json

{
  "watch": ["src"],
  "ext": "*",
  "ignore": ["src/**/*.spec.ts"],
  "exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
9reactions
LaThortillacommented, Mar 30, 2019

another option would be to create the ./src/orm.config.ts I have to import all the entities there and then add it in the main module.

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;
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM + Webpack causes SyntaxError: Unexpected token ...
The problem seems to be related to the fact that ormconfig.json is referring to .ts entity files. Solution in similar threads seems to...
Read more >
Unexpected token error from Webpack compiling React-node.js
You get this error if webpack can't find your .babelrc . Make sure you don't have a typo in the filename. You can...
Read more >
jest uuid syntaxerror: unexpected token 'export' - You.com
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >
nrwl-nx/community - Gitter
Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest...
Read more >
Hsqldb Unexpected Token: Getdate - ADocLib
Error: Unexpected token Entity name java sql hibernate hsqldb. ... [webpack start:hmr] SyntaxError: Unexpected token import on TypeORM entity What is the ...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found