inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

실전 프로젝트로 배우는 타입스크립트

[실습 안내] 국가별 코로나 정보 API 함수 타입 정의 방법 실습 안내

웹팩 에러 문의

849

choyeah

작성한 질문수 2

1

캠틴 판교님 안녕하세요. 너무나 훌륭한 강의에 큰 도움이 되었습니다. 감사합니다. :)

다름이 아니라 웹팩 번들링 시 에러가 발생되는데, 관련하여 도움이 될 수 있을만한 정보가 있을지 문의드립니다.

(참고로 빌드 관련 오류 문의를 확인하고 새롭게 올려주신 커밋본에서 수정된 부분을 적용시킨 상태에서 발생한 에러입니다.)

// tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "target": "ES5",
    "outDir": "./dist",
    "moduleResolution": "Node",
    "lib": ["ES2015", "DOM", "DOM.Iterable"],
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "strict": true,
    "esModuleInterop": true,
    "typeRoots": ["./node_modules/@types", "./types"]
  },
  "include": ["./src/**/*"],
  "exclude": ["node_modules", "dist"]
}
// webpack.config.js

const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
console.log("path.resolve(__dirname, 'dist')", path.resolve(__dirname, 'dist'))
module.exports = {
  mode: 'production',
  entry: './src/app.ts',
  output: {
    filename: 'app.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  plugins: [new webpack.ProgressPlugin(), new CleanWebpackPlugin()],
};
// package.json

{
  "name": "project",
  "version": "1.0.0",
  "description": "최종 프로젝트 폴더입니다",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.12.7",
    "@babel/preset-env": "^7.12.7",
    "@babel/preset-typescript": "^7.12.7",
    "@types/chart.js": "^2.9.30",
    "@typescript-eslint/eslint-plugin": "^4.8.1",
    "@typescript-eslint/parser": "^4.8.1",
    "clean-webpack-plugin": "^3.0.0",
    "eslint": "^7.14.0",
    "eslint-plugin-prettier": "^3.1.4",
    "prettier": "^2.2.0",
    "ts-loader": "^8.0.14",
    "typescript": "^4.1.2",
    "webpack": "^5.18.0",
    "webpack-cli": "^4.4.0"
  },
  "dependencies": {
    "axios": "^1.1.0",
    "chart.js": "^3.9.1"
  }
}
// index.html

...
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
    <script src="./dist/app.js"></script>
npm run build


> project@1.0.0 build
> webpack

orphan modules 154 KiB [orphan] 41 modules
runtime modules 670 bytes 3 modules
cacheable modules 500 KiB
  ./src/app.ts 11.2 KiB [built] [code generated]
  ./node_modules/axios/index.js + 40 modules 79.7 KiB [built] [code generated]
  ./node_modules/chart.js/dist/chart.mjs + 1 modules 409 KiB [built] [code generated]
  ./node_modules/form-data/lib/browser.js 101 bytes [built] [code generated]

ERROR in ./src/app.ts 44:14-38
Module not found: Error: Can't resolve './covid/index' in '/Users/xxx/Study/typescript/project/src'
resolve './covid/index' in '/Users/xxx/Study/typescript/project/src'
  using description file: /Users/xxx/Study/typescript/project/package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /Users/xxx/Study/typescript/project/package.json (relative path: ./src/covid/index)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/xxx/Study/typescript/project/src/covid/index doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/xxx/Study/typescript/project/src/covid/index.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /Users/xxx/Study/typescript/project/src/covid/index.json doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        /Users/xxx/Study/typescript/project/src/covid/index.wasm doesn't exist
      as directory
        /Users/xxx/Study/typescript/project/src/covid/index doesn't exist

webpack 5.74.0 compiled with 1 error in 2589 ms

 

es6 typescript

답변 2

0

choyeah

자답: webpack.config.js에 resolve 속성의 익스텐션 설정을 추가 후 웹팩 정상 번들링됨

 

const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
console.log("path.resolve(__dirname, 'dist')", path.resolve(__dirname, 'dist'))
module.exports = {
  mode: 'production',
  entry: './src/app.ts',
  output: {
    filename: 'app.js',
    path: path.resolve(__dirname, 'dist'),
  },
  resolve: { // <-- 추가한 부분
    extensions: ['.ts', '.js'],
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  plugins: [new webpack.ProgressPlugin(), new CleanWebpackPlugin()],
};

0

캡틴판교

안녕하세요, 웹팩에서 ./covid/index.js 모듈을 찾을 수 없다는 에러네요. 소스 코드 레벨에서 모듈 상대 경로가 잘 지정되어 있는지 확인해 보셔야 할 것 같아요! :)

-

0

137

1

[오류문의] import 에러

0

271

1

api가 중단된 건에 대하여..

1

379

2

프로젝트 완성본 github에 어디있나요?

1

348

2

https://api.covid19api.com/summary에 있는 원격 리소스를 차단

3

783

2

d.ts 컴파일 시 에러 질문 드립니다.

1

619

2

chartjs 타입시.. 직접 declare module chart.js로 하게 되면 내부의 구조를 모를 것 같은데요

1

594

2

COVID19 API 미작동(404) 질문

1

826

2

innerText부분 오류 문의.

1

681

2

Total Recovered가 화면에 0으로 나옵니다.

1

403

1

강의 내용 질문입니다.

2

443

1

요즘 바벨 사용 여부가 궁금합니다.

1

499

1

프로젝트 내 특정 파일만 Typing

1

571

1

소스질문

1

603

1

추후 강의에 관한 질문

2

402

1

rootdir, include 차이가 궁금합니다

1

675

1

Uncaught ReferenceError: exports is not defined 에러 해결

1

1832

1

function $(selector) 관련 질문 드립니다.

1

310

1

Uncaught ReferenceError: exports is not defined

1

469

1

innerHTML optional 체이닝

2

1922

1

화살표 함수 문법 소개 글 링크가 잘못되어 있습니다.

1

234

1

실전 적용 관련 질문 입니다.

1

301

1

모듈 알리아스(as) 질문 드립니다.

1

377

1

프리티어 안되시는 분들

1

389

1