• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

seed 생성 에러

22.02.07 17:26 작성 조회수 499

0

안녕하세요.

npm run seed:run 을하면 

 

🌱  TypeORM Seeding v1.6.1

✖ Could not load the config file!

TypeORMError: No connection options were found in any orm configuration files.

 

이런 에러가 발생해서

제로초님 깃허브로 전부 복사해도 똑같이 해결이안되는데 이유를 혹시 아시나요?

메세지를 보면 ormconfig.ts를 못찾는거같아요.

.env도 입력했고 프론트도 들어서 강의그대로 자동생성 진행했고, entities폴더도 깃허브로 바꿨어요. 그리고 package.json, ormconfig,create-initial-data 이런거 전부 복사해서 다시 해보고 경로도 맞아서 오타문제는 아닌거같은데..

 

 forRoot()부분에 옵션을 직접 넣어보기도 하고

엔티티부분을

entities: ["entities/*.js"] 이거도 해보고

entities: ["dist/**/**.entity{.ts,.js}"이렇게 바꿔보기도

package.json의 typeorm부분을

"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/ormconfig.ts",

이랗게 바꿔보기도 했는데 에러는 그대로 여서 잘 모르겠네용

 

답변 4

·

답변을 작성해보세요.

0

송봉준님의 프로필

송봉준

2022.07.27

🌱  TypeORM Seeding v1.6.1

✖ Could not load the config file!

TypeORMError: No connection options were found in any orm configuration files.

에러 원인 

ormconfig.ts을 밖으로 빼서 설정해주지 않으면 에러가 발생하네요 

0

삽질개발초보님의 프로필

삽질개발초보

2022.06.23

Error: Nest can't resolve dependencies of the ShopsService (ShopsRepository, ?). Please make sure that the argument UsersRepository at index [1] is available in the ShopsModule context.

 

Potential solutions:

- If UsersRepository is a provider, is it part of the current ShopsModule?

- If UsersRepository is exported from a separate @Module, is that module imported within ShopsModule?

  @Module({

    imports: [ /* the Module containing UsersRepository */ ]

  })

 

 

제로초님 이부분이 왜 에러가 나는것일까요..? 강의들으면서 궁금했습니다..

 

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Shops } from 'src/entities/shops.entity';
import { ShopsController } from './shops.controller';
import { ShopsService } from './shops.service';

@Module({
imports: [TypeOrmModule.forFeature([Shops])],
controllers: [ShopsController],
providers: [ShopsService],
})
export class ShopsModule {}

0

삽질개발초보님의 프로필

삽질개발초보

2022.06.21

제로초님 혹시 npm i typeorm-seeding 현재 이 명령어가 먹히질 않아서 그러는데 버전이 업데이트된것일까요 ?

어떤 에러메시지가 뜨시나요?

삽질개발초보님의 프로필

삽질개발초보

2022.06.23

npm err! 하면서 에러가 나오는데 제가 자세하게 캡쳐해서 드릴게요 ㅠㅠ

삽질개발초보님의 프로필

삽질개발초보

2022.06.23

제로초님 그리고 하나만 더 여쭤봐도될까요 ? 

//유저 상세정보 조회
async getUser(email: string) {
const getUser = await this.usersRepository
.createQueryBuilder()
.select(['tbl_user.email', 'tbl_user.user_name', 'tbl_user.gender'])
.from(Users, 'tbl_user')
.where('tbl_user.email = :email', { email })
.getOne();
if (!getUser) {
throw new BadRequestException('존재하지 않는 유저입니다.');
}
return getUser;
} 서비스쪽 로직입니다..
 
 
 
//컨트롤러
@ApiOperation({ summary: '내 정보 조회' })
@Get(':id')
async getUsers(@Param('email') email: string) {
return await this.usersService.getUser(email);
}
했는데 왜 해당쿼리 where절에서 ?값으로 Undefined가 찍히는지 이해가 안돼네요.. ㅋㅋㅋ 강의보면서 혼자 따로 만들어보고있는데

email이 undefined인 것 아닌가요?

@Get(':id')인데 @Param('email') 이네요.

삽질개발초보님의 프로필

삽질개발초보

2022.06.23

네 맞습니다 ㅠㅠ 전 email로 만들어 주었거든요.. 

@Get(':email') 하셔야죠

삽질개발초보님의 프로필

삽질개발초보

2022.06.23

그런데 service쪽에 이렇게 넣어주면 .where('tbl_user.email = :email', { email: 'dfadsfa@dafassaf.com'})

삽질개발초보님의 프로필

삽질개발초보

2022.06.23

.where('tbl_user.email = :email', { email: 'dfadsfa@dafassaf.com'}) 이렇게 넣어주면 동작은하네요

0

--config 부분을 typeorm 명령어 말고 seed:run에 추가해보세요.

그리고 .env에 다음것 말고도 db 연결 정보도 들어있으신가요?

TYPEORM_SEEDING_FACTORIES=src/factories/**/*{.ts,.js}
TYPEORM_SEEDING_SEEDS=src/seeds/**/*{.ts,.js}

음.. 제 깃허브로 해보니 됩니다. ㅠㅠ 코드와 버전이 같은지 한 번 더 확인해주세요.