Skip to content

fix(build): nest build 출력을 dist 루트로 정렬 (dist/main.js)#128

Merged
chanwoo7 merged 1 commit into
developfrom
fix/build-output-dist-root
Jun 6, 2026
Merged

fix(build): nest build 출력을 dist 루트로 정렬 (dist/main.js)#128
chanwoo7 merged 1 commit into
developfrom
fix/build-output-dist-root

Conversation

@chanwoo7
Copy link
Copy Markdown
Member

@chanwoo7 chanwoo7 commented Jun 6, 2026

Summary

nest build 산출물 경로 불일치로 인한 **운영 부팅 실패(잠복 결함)**를 고칩니다.

tsconfig.build.jsoninclude 가 없어 tsc 가 src + scripts + prisma 를 모두 컴파일 → 공통 루트가 프로젝트 루트가 되어 진입점이 dist/src/main.js 로 출력됐습니다. 반면 ecosystem.config.js(script: 'dist/main.js')와 package.json(start:prod: "node dist/main")은 dist/main.js 를 기대 → PM2/start 가 모듈을 못 찾아 부팅 실패. 자동 배포가 비활성(workflow_dispatch)이라 그동안 드러나지 않았습니다.

릴리즈 영향 점검 중 발견했습니다 (docs_*_develop-to-main-release-impact.md). 이 상태로 배포하면 PM2 start 단계에서 깨집니다.

Scope

변경: tsconfig.build.json

  • "include": ["src/**/*"] 추가 → 빌드가 src 만 컴파일, rootDir 이 src 로 잡혀 dist/main.js 로 출력
  • 결과적으로 nest-cli 에셋(dist/features/**/*.graphql) 및 실행 경로(ecosystem/start:prod)와 정합. ecosystem/start 스크립트는 변경 불필요(원래 기대 경로가 맞았음)

본 결함은 이번 클린아키텍처 리팩토링과 무관한 사전 결함(3월 @/ alias 마이그레이션 이후)이나, 릴리즈/배포 전 반드시 선행되어야 함.

진행 상황

Impact

  • FE / DB / 런타임 동작: 영향 없음 (빌드 출력 위치만 변경, 컴파일 결과·로직 동일).
  • 빌드: dist/main.js 로 출력 (이전 dist/src/main.js). dist/src/·dist/scripts/·dist/prisma/(루트 prisma 디렉터리 산출물) 등 불필요 산출물 제거 → 번들 정리.
  • 배포: PM2 script: dist/main.js 부팅 정상화. 이 수정 없이는 배포 시 부팅 실패.

Test plan

  • yarn builddist/main.js 생성 확인, dist/src/ 부재 확인, dist/features/*.graphql 에셋 유지
  • 부팅 테스트: node dist/main.js 가 전체 모듈 그래프·DI 해석 후 DB 연결 단계까지 도달 (Cannot find module/Nest can't resolve 없음). DB 미연결 에러만 발생 = 코드/경로 정상
  • 컴파일된 상대 import(require("./...")) 가 새 루트에서 정합
  • CI 통과 확인

tsconfig.build.json 에 include: ["src/**/*"] 추가. 기존엔 include 부재로 tsc 가
src+scripts+prisma 전체를 컴파일 → 공통 루트가 프로젝트 루트가 되어 dist/src/main.js
로 출력됐고, ecosystem.config.js(script: dist/main.js)·start:prod(node dist/main)
와 불일치해 PM2 부팅 실패가 잠복(자동배포 비활성으로 미발견).

src 만 컴파일하도록 제한 → dist/main.js 로 출력. nest-cli 에셋(dist/features/) 및
실행 경로와 정합. 부팅 테스트로 모듈해석·DI 정상 확인(DB 연결 단계 도달).
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 6, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2516a69f-38d0-4dd0-b50f-8fabceb0db96

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/build-output-dist-root

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c43b5baa4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tsconfig.build.json
@@ -1,4 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*"],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add alias resolution for the relocated entrypoint

When production starts the newly generated dist/main.js via node dist/main or PM2's dist/main.js, the emitted file still contains imports like @/app.module from src/main.ts; TypeScript paths only affects type resolution and does not rewrite those module specifiers. Since the runtime commands do not preload tsconfig-paths/register or run an alias-rewrite step, this change gets past the previous missing-file error but then crashes with Cannot find module '@/app.module' before the app boots.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive. dist/**/*.js에 @/ specifier 0개 — nest build가 전부 상대경로(require("./app.module"))로 emit함. NODE_ENV=production node dist/main 부팅 시 InstanceLoader까지 진입(모듈 전부 로드 성공), DOCS_ACCESS_TOKEN env 가드에서 멈춤. Cannot find module 미발생.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 97.42% 3555/3649
🟢 Branches 93.83% 1125/1199
🟢 Functions 94.09% 653/694
🟢 Lines 97.66% 3253/3331

Test suite run success

1254 tests passing in 146 suites.

Report generated by 🧪jest coverage report action from c43b5ba

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chanwoo7 chanwoo7 merged commit 7a5774b into develop Jun 6, 2026
10 checks passed
@chanwoo7 chanwoo7 deleted the fix/build-output-dist-root branch June 6, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant