• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

핫리로딩으로 공식문서와 동일하게 적용했는데 찾을 수 없다고만 뜨는데 이유가 뭘까요??

23.07.23 22:21 작성 조회수 289

0

핫리로딩으로 공식문서와 동일하게 적용했는데 찾을 수 없다고만 뜨는데 이유가 뭘까요??

아래 작성 코드 확인부탁드립니다!

 

  • 터미널 에러

PS C:\nestStudy\slack-clone-app\a-nest> npm run start:dev

> a-nest@0.0.1 start:dev
> nest build --webpack --webpackPath webpack-hmr.config.js --watch    


 Error  Cannot find module 'C:\nestStudy\slack-clone-app\a-nest\webpack-hmr.config.js'
Require stack:
- C:\nestStudy\slack-clone-app\a-nest\node_modules\@nestjs\cli\actions\build.action.js
- C:\nestStudy\slack-clone-app\a-nest\node_modules\@nestjs\cli\actions\index.js
- C:\nestStudy\slack-clone-app\a-nest\node_modules\@nestjs\cli\commands\command.loader.js
- C:\nestStudy\slack-clone-app\a-nest\node_modules\@nestjs\cli\commands\index.js
- C:\nestStudy\slack-clone-app\a-nest\node_modules\@nestjs\cli\bin\nest.js

 

  • main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

declare const module: any;

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const port = process.env.PORT || 3000;
  await app.listen(3000);
  console.log(`listening on port ${port}`);

  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => app.close());
  }
}

bootstrap();

 

  • webpack-hmr.config.js

const nodeExternals = require('webpack-node-externals');
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');

module.exports = function (options, webpack) {
  return {
    ...options,
    entry: ['webpack/hot/poll?100', options.entry],
    externals: [
      nodeExternals({
        allowlist: ['webpack/hot/poll?100'],
      }),
    ],
    plugins: [
      ...options.plugins,
      new webpack.HotModuleReplacementPlugin(),
      new webpack.WatchIgnorePlugin({
        paths: [/\.js$/, /\.d\.ts$/],
      }),
      new RunScriptWebpackPlugin({ name: options.output.filename, autoRestart: false }),
    ],
  };
};

 

  • package.json

{
  "name": "a-nest",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev-backup": "nest start --watch",
    "start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/platform-express": "^10.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.59.11",
    "@typescript-eslint/parser": "^5.59.11",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-plugin-prettier": "^4.2.1",
    "jest": "^29.5.0",
    "prettier": "^2.8.8",
    "run-script-webpack-plugin": "^0.2.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3",
    "webpack": "^5.88.2",
    "webpack-node-externals": "^3.0.0"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

 

 

 

 

답변 1

답변을 작성해보세요.

1

webpack-hmr.config.js가 a-nest 폴더 안에 존재하나요?

dev kim님의 프로필

dev kim

질문자

2023.07.24

안에 추가한 줄 알았는데 밖에 추가가 되있었습니다..! 감사합니다ㅠ