1. 문제 정의

  2. 사실 수집

    Protobuf 파일 로드 중 오류가 발생했습니다: Error: ENOENT: no such file or directory, scandir 'D:\\github\\super-convergenc
    │ e-msa-server\\apps\\ice\\protobuf'
    │     at Object.readdirSync (node:fs:1506:26)
    │     at O (file:///D:/github/super-convergence-msa-server/apps/ice/dist/server.js:1:820)
    │     at L (file:///D:/github/super-convergence-msa-server/apps/ice/dist/server.js:1:967)
    │     at C.initialize (file:///D:/github/super-convergence-msa-server/apps/ice/dist/server.js:1:6020)
    │     at C.start (file:///D:/github/super-convergence-msa-server/apps/ice/dist/server.js:1:6075)
    │     at file:///D:/github/super-convergence-msa-server/apps/ice/dist/server.js:8:436
    │     at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
    │     at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
    │     at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5) {
    │   errno: -4058,
    │   code: 'ENOENT',
    │   syscall: 'scandir',
    │   path: 'D:\\\\github\\\\super-convergence-msa-server\\\\apps\\\\ice\\\\protobuf'
    │ }
    
  3. 원인 추론

  4. 해결 방안

    a. proto 파일도 같이 빌드 시킨다.

    → 컨테이너로 배포할 때 결국 포함시켜야 함. → 시도

    b. 상위에 있는 proto 파일을 읽어오게 경로를 수정한다.

    → 컨테이너로 배포할 때 결국 수정해야 함. → 기각

  5. 해결 시도

    // 빌드 때 protobuf로 복사해서 생성시킨다.
    export const buildServiceWithProto = async (options) => {
      const srcProtoDir = path.resolve(
        process.cwd(),
        "../../packages/common/protobuf"
      );
      const destProtoDir = path.resolve(process.cwd(), "./dist/protobuf");
    
      try {
        await fs.mkdir(destProtoDir, { recursive: true });
        await fs.cp(srcProtoDir, destProtoDir, { recursive: true });
    
        await buildService(options);
      } catch (error) {
        console.error("Build failed:", error);
        process.exit(1);
      }
    };
    
     $ node dist/server.js
    │ Protobuf initialized : 14
    │ distributor server listening on port 9000
    │  [ _onConnection ] distributor server : =>  ::ffff:127.0.0.1 : 5591
    │ [ _onCreate ]  ::ffff:127.0.0.1 5591
    │  [ createServerInfoNotification ] payload ===>>  {
    │   params: [
    │     {
    │       name: 'distributor',
    │       number: 1,
    │       host: 'localhost',
    │       port: '9000',
    │       types: []
    │     }
    │   ]
    │ }
    │   [ serialize ] payload ===>>>  {
    │   serverInfoNotification: S2S_ServerInfoNotification { params: [ [Object] ] }
    │ }
    

    문제는 해결되었으나 배포 때 결국 수정해야 함 → 상위 경로를 참조하기 때문

    {
      "name": "@repo/common",
      "version": "0.0.0",
      "type": "module",
      "private": true,
      "license": "MIT",
      "exports": {
        "./utils": "./utils/index.js",
        "./classes": "./classes/index.js",
        "./config": "./config/index.js",
        "./header": "./constants/header.js",
        "./handlers": "./handlers/index.js",
        "./load.protos": "./init/load.protos.js",
        "./protobuf": "./protobuf" // protobuf 명으로 사용
      },
      "files": [
        "utils/**/*",
        "classes/**/*",
        "config/**/*",
        "constants/**/*",
        "handlers/**/*",
        "init/**/*",
        "protobuf/**/*.proto"  // proto 파일들을 포함
      ]
    }
    
  6. 해결

    컨테이너로 배포 시에도 같은 node_modules 폴더의 protobuf를 참조하기 때문에 문제 발생 x