작성
·
550
1
import { Channels } from '../../entities/channel.entity';
import { Workspaces } from 'src/entities/workspace.entity';
import { DataSource } from 'typeorm';
import { Seeder, SeederFactoryManager } from 'typeorm-extension';
export default class UserSeeder implements Seeder {
async run(
dataSource: DataSource,
factoryManager: SeederFactoryManager,
): Promise<any> {
const workspaceRepository = dataSource.getRepository(Workspaces);
await workspaceRepository.insert([
{
id: 1,
name: 'nest-practice',
url: 'nest-practice',
},
]);
const channelsRepository = dataSource.getRepository(Channels);
await channelsRepository.insert([
{
id: 1,
name: '개인',
WorkspaceId: 1,
private: true,
},
]);
}
}
에러 로그
BaseError: Cannot find module 'src/entities/workspace.entity'
Require stack:
- /Users/jinyoung/Desktop/study/nest/nest-project/src/database/seeds/create-initial-data.ts
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/locter/dist/index.cjs
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/utils/file-path.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/utils/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/factory/module.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/factory/manager.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/factory/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/data-source/options/module.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/data-source/options/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/data-source/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/database/create.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/database/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/index.js
- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/index.js
at ModuleLoader.loadSync (/Users/jinyoung/Desktop/study/nest/nest-project/node_modules/locter/src/loader/built-in/module/module.ts:179:23)
at ModuleLoader.loadSync (/Users/jinyoung/Desktop/study/nest/nest-project/node_modules/locter/src/loader/built-in/module/module.ts:172:37)
at ModuleLoader.execute (/Users/jinyoung/Desktop/study/nest/nest-project/node_modules/locter/src/loader/built-in/module/module.ts:55:31)
at async prepareSeeder (/Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/module.js:58:39)
at async runSeeders (/Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/module.js:111:19)
at async Object.handler (/Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/seed.js:59:9) {
options: {
code: 'MODULE_NOT_FOUND',
message: "Cannot find module 'src/entities/workspace.entity'\n" +
'Require stack:\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/src/database/seeds/create-initial-data.ts\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/locter/dist/index.cjs\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/utils/file-path.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/utils/index.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/factory/module.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/factory/manager.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/factory/index.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/seeder/index.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/data-source/options/module.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/data-source/options/index.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/data-source/index.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/database/create.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/database/index.js\n' +
'- /Users/jinyoung/Desktop/study/nest/nest-project/node_modules/typeorm-extension/dist/cli/commands/index.js\n' +
해당 코드에서 처음엔 Channels라는 엔티티경로를 인식해오지 못한다고 에러 로그를 받았습니다. 이거저거 해보다가 아 혹시 상대경로로 바꿔주면 인식이 될까? 해서 상대경로로 바꿔 주었더니 Channels가 인식되기 시작했습니다. 궁금한점은 처음 Import해올 당시 제가 경로를 직접입력한것이 아닌 타입스크립트가 자동으로 경로를 잡아주어 import했습니다. 하지만 어째서 타입스크립트가 인식해서 잡아준 경로에 존재하는 모듈을 찾을수 없다고 나오는지 모르겠습니다.
답변 2
0
0
src로 시작하는 경로는 node_modules 안에 src라는 패키지 내부 경로입니다. 즉 말도 안 되는 경로인 것이죠. tsconfig.json에서 path를 설정하지 않는 이상 그런 의미입니다.
타입스크립트가 잡아준 게 아니라 에디터가 잡아준 거 아닌가요?
오,,, 지금까지 타입스크립트가 잡아줬다고 생각했는데 에디터가 잡아준거였군요... 감사합니다!!