Nestjs repository pattern config challenge
I'm trying to figure out how the "Repository Pattern" of TypeOrm in Nest works. I would like to have a resources
file in which a local
and a remote file hold the different entites, controllers, modules etc. See screenshot
When the app is building I`m getting the following error:
[Nest] 3186 - 11/19/2018, 10:44:43 PM [ExceptionHandler] No repository for "Project" was found. Looks like this entity is not registered in current "default" connection? +1ms
From the Nest and TypeORM documentation I can triangulate, that I have to tell the application where it can find the entities or at least this is what I believe the error is trying to tell me.
I'm using a .env
to pull the config for TypeORM in:
TYPEORM_CONNECTION = postgres
TYPEORM_HOST = localhost
TYPEORM_USERNAME = xyz
TYPEORM_PASSWORD = xyz
TYPEORM_DATABASE = xyz
TYPEORM_PORT = 5432
TYPEORM_SYNCHRONIZE = true
TYPEORM_LOGGING = true
TYPEORM_ENTITIES = src/server/**/**.entity{.ts,.js}
app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AngularUniversalModule } from './modules/angular-universal/angular-universal.module';
import { JiraService } from './services/jira.service'
// modules
import { ProjectModule } from './resources/local/project/project.module'
// sync
import {ProjectsSync} from './sync/projects.sync'
@Module({
imports: [
ProjectModule,
TypeOrmModule.forRoot(),
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
project.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ProjectService } from './project.service';
import { ProjectController } from './project.controller';
import { Project } from './project.entity';
@Module({
imports: [TypeOrmModule.forFeature([Project])],
providers: [ProjectService],
controllers: [ProjectController],
})
export class ProjectModule {}
project.service.ts
import { Injectable, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Project } from './project.entity';
@Injectable()
export class ProjectService {
constructor(
@InjectRepository(Project)
private readonly projectRepository: Repository<Project>,
) {}
async findAll(): Promise<Project> {
return await this.projectRepository.find();
}
}
project.entity.ts
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Project {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 500 })
name: string;
}
project.controller.ts
import { Controller, Get } from '@nestjs/common';
import { ProjectService } from './project.service';
import { Project } from './project.entity';
@Controller('project')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}
@Get()
findAll(): Promise<Project> {
return this.projectService.findAll();
}
}
node.js typescript nestjs
add a comment |
I'm trying to figure out how the "Repository Pattern" of TypeOrm in Nest works. I would like to have a resources
file in which a local
and a remote file hold the different entites, controllers, modules etc. See screenshot
When the app is building I`m getting the following error:
[Nest] 3186 - 11/19/2018, 10:44:43 PM [ExceptionHandler] No repository for "Project" was found. Looks like this entity is not registered in current "default" connection? +1ms
From the Nest and TypeORM documentation I can triangulate, that I have to tell the application where it can find the entities or at least this is what I believe the error is trying to tell me.
I'm using a .env
to pull the config for TypeORM in:
TYPEORM_CONNECTION = postgres
TYPEORM_HOST = localhost
TYPEORM_USERNAME = xyz
TYPEORM_PASSWORD = xyz
TYPEORM_DATABASE = xyz
TYPEORM_PORT = 5432
TYPEORM_SYNCHRONIZE = true
TYPEORM_LOGGING = true
TYPEORM_ENTITIES = src/server/**/**.entity{.ts,.js}
app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AngularUniversalModule } from './modules/angular-universal/angular-universal.module';
import { JiraService } from './services/jira.service'
// modules
import { ProjectModule } from './resources/local/project/project.module'
// sync
import {ProjectsSync} from './sync/projects.sync'
@Module({
imports: [
ProjectModule,
TypeOrmModule.forRoot(),
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
project.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ProjectService } from './project.service';
import { ProjectController } from './project.controller';
import { Project } from './project.entity';
@Module({
imports: [TypeOrmModule.forFeature([Project])],
providers: [ProjectService],
controllers: [ProjectController],
})
export class ProjectModule {}
project.service.ts
import { Injectable, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Project } from './project.entity';
@Injectable()
export class ProjectService {
constructor(
@InjectRepository(Project)
private readonly projectRepository: Repository<Project>,
) {}
async findAll(): Promise<Project> {
return await this.projectRepository.find();
}
}
project.entity.ts
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Project {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 500 })
name: string;
}
project.controller.ts
import { Controller, Get } from '@nestjs/common';
import { ProjectService } from './project.service';
import { Project } from './project.entity';
@Controller('project')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}
@Get()
findAll(): Promise<Project> {
return this.projectService.findAll();
}
}
node.js typescript nestjs
You won't be able to run correctly with node (not ts-node) as you need to parse entities withindist
and notsrc
. Personally I prefer using a factory method to instanciate the TypeOrm connection so I can change this path depending on env (and parsing other props from env files within code).
– zenbeni
Nov 23 at 9:34
add a comment |
I'm trying to figure out how the "Repository Pattern" of TypeOrm in Nest works. I would like to have a resources
file in which a local
and a remote file hold the different entites, controllers, modules etc. See screenshot
When the app is building I`m getting the following error:
[Nest] 3186 - 11/19/2018, 10:44:43 PM [ExceptionHandler] No repository for "Project" was found. Looks like this entity is not registered in current "default" connection? +1ms
From the Nest and TypeORM documentation I can triangulate, that I have to tell the application where it can find the entities or at least this is what I believe the error is trying to tell me.
I'm using a .env
to pull the config for TypeORM in:
TYPEORM_CONNECTION = postgres
TYPEORM_HOST = localhost
TYPEORM_USERNAME = xyz
TYPEORM_PASSWORD = xyz
TYPEORM_DATABASE = xyz
TYPEORM_PORT = 5432
TYPEORM_SYNCHRONIZE = true
TYPEORM_LOGGING = true
TYPEORM_ENTITIES = src/server/**/**.entity{.ts,.js}
app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AngularUniversalModule } from './modules/angular-universal/angular-universal.module';
import { JiraService } from './services/jira.service'
// modules
import { ProjectModule } from './resources/local/project/project.module'
// sync
import {ProjectsSync} from './sync/projects.sync'
@Module({
imports: [
ProjectModule,
TypeOrmModule.forRoot(),
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
project.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ProjectService } from './project.service';
import { ProjectController } from './project.controller';
import { Project } from './project.entity';
@Module({
imports: [TypeOrmModule.forFeature([Project])],
providers: [ProjectService],
controllers: [ProjectController],
})
export class ProjectModule {}
project.service.ts
import { Injectable, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Project } from './project.entity';
@Injectable()
export class ProjectService {
constructor(
@InjectRepository(Project)
private readonly projectRepository: Repository<Project>,
) {}
async findAll(): Promise<Project> {
return await this.projectRepository.find();
}
}
project.entity.ts
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Project {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 500 })
name: string;
}
project.controller.ts
import { Controller, Get } from '@nestjs/common';
import { ProjectService } from './project.service';
import { Project } from './project.entity';
@Controller('project')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}
@Get()
findAll(): Promise<Project> {
return this.projectService.findAll();
}
}
node.js typescript nestjs
I'm trying to figure out how the "Repository Pattern" of TypeOrm in Nest works. I would like to have a resources
file in which a local
and a remote file hold the different entites, controllers, modules etc. See screenshot
When the app is building I`m getting the following error:
[Nest] 3186 - 11/19/2018, 10:44:43 PM [ExceptionHandler] No repository for "Project" was found. Looks like this entity is not registered in current "default" connection? +1ms
From the Nest and TypeORM documentation I can triangulate, that I have to tell the application where it can find the entities or at least this is what I believe the error is trying to tell me.
I'm using a .env
to pull the config for TypeORM in:
TYPEORM_CONNECTION = postgres
TYPEORM_HOST = localhost
TYPEORM_USERNAME = xyz
TYPEORM_PASSWORD = xyz
TYPEORM_DATABASE = xyz
TYPEORM_PORT = 5432
TYPEORM_SYNCHRONIZE = true
TYPEORM_LOGGING = true
TYPEORM_ENTITIES = src/server/**/**.entity{.ts,.js}
app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AngularUniversalModule } from './modules/angular-universal/angular-universal.module';
import { JiraService } from './services/jira.service'
// modules
import { ProjectModule } from './resources/local/project/project.module'
// sync
import {ProjectsSync} from './sync/projects.sync'
@Module({
imports: [
ProjectModule,
TypeOrmModule.forRoot(),
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
project.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ProjectService } from './project.service';
import { ProjectController } from './project.controller';
import { Project } from './project.entity';
@Module({
imports: [TypeOrmModule.forFeature([Project])],
providers: [ProjectService],
controllers: [ProjectController],
})
export class ProjectModule {}
project.service.ts
import { Injectable, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Project } from './project.entity';
@Injectable()
export class ProjectService {
constructor(
@InjectRepository(Project)
private readonly projectRepository: Repository<Project>,
) {}
async findAll(): Promise<Project> {
return await this.projectRepository.find();
}
}
project.entity.ts
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Project {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 500 })
name: string;
}
project.controller.ts
import { Controller, Get } from '@nestjs/common';
import { ProjectService } from './project.service';
import { Project } from './project.entity';
@Controller('project')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}
@Get()
findAll(): Promise<Project> {
return this.projectService.findAll();
}
}
node.js typescript nestjs
node.js typescript nestjs
asked Nov 19 at 21:59
Tino
1,23031947
1,23031947
You won't be able to run correctly with node (not ts-node) as you need to parse entities withindist
and notsrc
. Personally I prefer using a factory method to instanciate the TypeOrm connection so I can change this path depending on env (and parsing other props from env files within code).
– zenbeni
Nov 23 at 9:34
add a comment |
You won't be able to run correctly with node (not ts-node) as you need to parse entities withindist
and notsrc
. Personally I prefer using a factory method to instanciate the TypeOrm connection so I can change this path depending on env (and parsing other props from env files within code).
– zenbeni
Nov 23 at 9:34
You won't be able to run correctly with node (not ts-node) as you need to parse entities within
dist
and not src
. Personally I prefer using a factory method to instanciate the TypeOrm connection so I can change this path depending on env (and parsing other props from env files within code).– zenbeni
Nov 23 at 9:34
You won't be able to run correctly with node (not ts-node) as you need to parse entities within
dist
and not src
. Personally I prefer using a factory method to instanciate the TypeOrm connection so I can change this path depending on env (and parsing other props from env files within code).– zenbeni
Nov 23 at 9:34
add a comment |
1 Answer
1
active
oldest
votes
Just a wild guess, have you tried:
TYPEORM_ENTITIES = ./server/**/**.entity{.ts,.js}
And/or switching the imports in app.module.ts putting the TypeOrmModule first:
@Module({
imports: [
TypeOrmModule.forRoot(),
ProjectModule,
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383242%2fnestjs-repository-pattern-config-challenge%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just a wild guess, have you tried:
TYPEORM_ENTITIES = ./server/**/**.entity{.ts,.js}
And/or switching the imports in app.module.ts putting the TypeOrmModule first:
@Module({
imports: [
TypeOrmModule.forRoot(),
ProjectModule,
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
add a comment |
Just a wild guess, have you tried:
TYPEORM_ENTITIES = ./server/**/**.entity{.ts,.js}
And/or switching the imports in app.module.ts putting the TypeOrmModule first:
@Module({
imports: [
TypeOrmModule.forRoot(),
ProjectModule,
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
add a comment |
Just a wild guess, have you tried:
TYPEORM_ENTITIES = ./server/**/**.entity{.ts,.js}
And/or switching the imports in app.module.ts putting the TypeOrmModule first:
@Module({
imports: [
TypeOrmModule.forRoot(),
ProjectModule,
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
Just a wild guess, have you tried:
TYPEORM_ENTITIES = ./server/**/**.entity{.ts,.js}
And/or switching the imports in app.module.ts putting the TypeOrmModule first:
@Module({
imports: [
TypeOrmModule.forRoot(),
ProjectModule,
AngularUniversalModule.forRoot(),
],
controllers: ,
providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}
edited Nov 20 at 15:02
answered Nov 20 at 10:38
Lewsmith
458
458
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383242%2fnestjs-repository-pattern-config-challenge%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You won't be able to run correctly with node (not ts-node) as you need to parse entities within
dist
and notsrc
. Personally I prefer using a factory method to instanciate the TypeOrm connection so I can change this path depending on env (and parsing other props from env files within code).– zenbeni
Nov 23 at 9:34