jiphyeonjeon-42 / backend-nest

6차 개발팀은 nestjs 로 새로 작성하기로 했습니다
MIT License
0 stars 0 forks source link

Error: Cannot find module '@nestjs/common' #62

Closed nyj001012 closed 2 months ago

nyj001012 commented 2 months ago

개요

pnpm start:dev@nestjs/common 모듈을 찾지 못하는 문제 발생

로그

[오후 9:13:09] Starting compilation in watch mode...

[오후 9:13:11] Found 0 errors. Watching for file changes.

node:internal/modules/cjs/loader:1251
  throw err;
  ^

Error: Cannot find module '@nestjs/common'
Require stack:
- /Users/nayejin/dev/42_Seoul/backend-nest/node_modules/nestjs-zod/dist/index.js
- /Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/histories/histories.controller.js
- /Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/histories/histories.module.js
- /Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/app.module.js
- /Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/main.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/Users/nayejin/dev/42_Seoul/backend-nest/node_modules/nestjs-zod/dist/index.js:5:14)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/nayejin/dev/42_Seoul/backend-nest/node_modules/nestjs-zod/dist/index.js',
    '/Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/histories/histories.controller.js',
    '/Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/histories/histories.module.js',
    '/Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/app.module.js',
    '/Users/nayejin/dev/42_Seoul/backend-nest/backend/dist/main.js'
  ]
}

Node.js v22.9.0

시도해본 것

scarf005 commented 2 months ago
📦[scarf@node-slim backend]$ pnpm start dev

> backend@0.0.1 start /run/media/home/scarf/repo/lib42/backend-nest/backend
> nest start "dev"

src/histories/histories.controller.ts:6:30 - error TS2307: Cannot find module 'nestjs-zod' or its corresponding type declarations.

6 import { zodToOpenAPI } from 'nestjs-zod';
                               ~~~~~~~~~~~~

Found 1 error(s).

 ELIFECYCLE  Command failed with exit code 1

존재하지 않는 nestjs-zod에서 zodToOpenAPI를 가져오려고 시도하면서 발생한 오류인데 다른 오류 메시지가 나오는 것 같습니다.

diff --git a/backend/src/histories/histories.controller.ts b/backend/src/histories/histories.controller.ts
index ce2b9fa..6189f18 100644
--- a/backend/src/histories/histories.controller.ts
+++ b/backend/src/histories/histories.controller.ts
@@ -3,7 +3,9 @@ import { ApiOperation, ApiResponse } from '@nestjs/swagger';
 import { HistoriesService } from 'src/histories/histories.service';
 import { getHistoriesDto } from 'src/histories/dto/histories.dto'; // Adjust the import path as necessary
 import { getHistoriesResponseSchema } from './schema/histories.schema';
-import { zodToOpenAPI } from 'nestjs-zod';
+import { createZodDto } from '@anatine/zod-nestjs';
+
+class HistoriesResponseDTO extends createZodDto(getHistoriesResponseSchema) {}

 @Controller('histories')
 export class HistoriesController {
@@ -19,7 +21,7 @@ export class HistoriesController {
   @ApiResponse({
     status: 200,
     description: '대출 기록을 반환한다.',
-    schema: zodToOpenAPI(getHistoriesResponseSchema),
+    type: HistoriesResponseDTO,
   })
   getHistories(@Query() query: getHistoriesDto) {
     return this.historiesService.getHistories();

다음과 같이 수정한 후 다시 시도해보시겠어요?

nyj001012 commented 2 months ago
📦[scarf@node-slim backend]$ pnpm start dev

> backend@0.0.1 start /run/media/home/scarf/repo/lib42/backend-nest/backend
> nest start "dev"

src/histories/histories.controller.ts:6:30 - error TS2307: Cannot find module 'nestjs-zod' or its corresponding type declarations.

6 import { zodToOpenAPI } from 'nestjs-zod';
                               ~~~~~~~~~~~~

Found 1 error(s).

 ELIFECYCLE  Command failed with exit code 1

존재하지 않는 nestjs-zod에서 zodToOpenAPI를 가져오려고 시도하면서 발생한 오류인데 다른 오류 메시지가 나오는 것 같습니다.

diff --git a/backend/src/histories/histories.controller.ts b/backend/src/histories/histories.controller.ts
index ce2b9fa..6189f18 100644
--- a/backend/src/histories/histories.controller.ts
+++ b/backend/src/histories/histories.controller.ts
@@ -3,7 +3,9 @@ import { ApiOperation, ApiResponse } from '@nestjs/swagger';
 import { HistoriesService } from 'src/histories/histories.service';
 import { getHistoriesDto } from 'src/histories/dto/histories.dto'; // Adjust the import path as necessary
 import { getHistoriesResponseSchema } from './schema/histories.schema';
-import { zodToOpenAPI } from 'nestjs-zod';
+import { createZodDto } from '@anatine/zod-nestjs';
+
+class HistoriesResponseDTO extends createZodDto(getHistoriesResponseSchema) {}

 @Controller('histories')
 export class HistoriesController {
@@ -19,7 +21,7 @@ export class HistoriesController {
   @ApiResponse({
     status: 200,
     description: '대출 기록을 반환한다.',
-    schema: zodToOpenAPI(getHistoriesResponseSchema),
+    type: HistoriesResponseDTO,
   })
   getHistories(@Query() query: getHistoriesDto) {
     return this.historiesService.getHistories();

다음과 같이 수정한 후 다시 시도해보시겠어요?

PATHnode_modules 경로 등록해두니까 실행됐네요, zodToOpenAPI는 import되어 있는 상태예요