@kamilmysliwiec
I have created a repo I have built typeorm - jest - class-validator - passport all is fine but when I run the command "npm run start: prod" the following error message appears, I thought that this is a bad configuration but I tested the command in the application "01-cats-app" but the error always appears
E:\Projets\WebStorm\01-cats-app\01-cats-app>npm run start:prod
> [email protected] prestart:prod E:\Projets\WebStorm\01-cats-app\01-cats-app
> tsc
node_modules/@types/jest/index.d.ts(14,13): error TS2300: Duplicate identifier 'beforeEach'.
node_modules/@types/jest/index.d.ts(16,13): error TS2300: Duplicate identifier 'afterEach'.
node_modules/@types/mocha/index.d.ts(33,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'describe' must be of type 'Describe', but here has type 'IContextDefinition'.
node_modules/@types/mocha/index.d.ts(34,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'xdescribe' must be of type 'Describe', but here has type 'IContextDefinition'.
node_modules/@types/mocha/index.d.ts(39,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'it' must be of type 'It', but here has type 'ITestDefinition'.
node_modules/@types/mocha/index.d.ts(40,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'xit' must be of type 'It', but here has type 'ITestDefinition'.
node_modules/@types/mocha/index.d.ts(42,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'test' must be of type 'It', but here has type 'ITestDefinition'.
node_modules/@types/mocha/index.d.ts(60,18): error TS2300: Duplicate identifier 'beforeEach'.
node_modules/@types/mocha/index.d.ts(61,18): error TS2300: Duplicate identifier 'beforeEach'.
node_modules/@types/mocha/index.d.ts(62,18): error TS2300: Duplicate identifier 'afterEach'.
node_modules/@types/mocha/index.d.ts(63,18): error TS2300: Duplicate identifier 'afterEach'.
thanks for help
[Nest] 412 - 2017-10-11 21:58:46 [NestFactory] Starting Nest application...
[Nest] 412 - 2017-10-11 21:58:46 [InstanceLoader] ApplicationModule dependencies initialized +16ms
[Nest] 412 - 2017-10-11 21:58:46 [ExceptionHandler] Unexpected token import
E:\Projets\WebStorm\learning-nest\server\src\modules\cats\entitys\cat.entity.ts:2
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:588:28)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
Hi @elrhourha,
We need more code here. It seems that it's not Nest related issue, perhaps something with the ts/babel/libs configuration.
Hi @elrhourha did you find out the solution ? I have the same problem...
For everyone that gets this error in the examples, look in the ormconfig.json
file, it looks for entities in the src directory.
When you run npm run start:prod
the entities will be in the dist directory.
Hi everyone,
I encountered the same issue and could not find a solution provided by the framework itself.
This made me wonder, because to me the root cause for that issue is the missing support for different environments.
Even the example 05-sql-typeorm will not if you start it for production with npm run start:prod
.
I've craeted a fork of the typescript-starter repository and added support for different environments, similar to how I think angular does it.
The changes required you'll find within this commit.
@kamilmysliwiec maybe you want to have a look at it? It would be nice if something like this would be provided by the framework itself. probably by something like an nest-cli.
I found the problem.
It's related to TypeORM's ormconfig.json. By default it looks for entities in the /src
folder and opens TypeScript files instead of the Javascript compiled ones.
The solution I found was using a dynamic ormconfig.js (instead of .json) that has a conditional path. Docs here => http://typeorm.io/#/using-ormconfig/loading-from-ormconfigjs
In my case my ormconfig.js looks like that (assuming that you have a dotenv variable called NODE_ENV) :
const SOURCE_PATH = process.env.NODE_ENV === 'production' ? 'dist' : 'src'
module.exports = {
type: 'sqlite',
database: './db/myDatabase.db',
entities: [`${SOURCE_PATH}/**/**.entity{.ts,.js}`],
}
thanks @brunobuddy !!
@Sh4bbY
Thank you so much, it's the only thing that worked for me!
@brunobuddy Are you also using a conditional path for the migrations
, subscribers
, and cli
properties?
I found the problem.
It's related to TypeORM's ormconfig.json. By default it looks for entities in the
/src
folder and opens TypeScript files instead of the Javascript compiled ones.The solution I found was using a dynamic ormconfig.js (instead of .json) that has a conditional path. Docs here => http://typeorm.io/#/using-ormconfig/loading-from-ormconfigjs
In my case my ormconfig.js looks like that (assuming that you have a dotenv variable called NODE_ENV) :
const SOURCE_PATH = process.env.NODE_ENV === 'production' ? 'dist' : 'src' module.exports = { type: 'sqlite', database: './db/myDatabase.db', entities: [`${SOURCE_PATH}/**/**.entity{.ts,.js}`], }
@brunobuddy this solutions worked for me too, but now I am stucked on migrations folder... :cry:
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.
Most helpful comment
I found the problem.
It's related to TypeORM's ormconfig.json. By default it looks for entities in the
/src
folder and opens TypeScript files instead of the Javascript compiled ones.The solution I found was using a dynamic ormconfig.js (instead of .json) that has a conditional path. Docs here => http://typeorm.io/#/using-ormconfig/loading-from-ormconfigjs
In my case my ormconfig.js looks like that (assuming that you have a dotenv variable called NODE_ENV) :