Webpack reported an error when configuring typescript

I. my project"s basic configuration

  • 1, package.json

    ERROR in ./src/index.ts 6:9
    Module parse failed: Unexpected token (6:9)
    You may need an appropriate loader to handle this file type.
    |
    | class Demo {
    >   public name: string;
    |   constructor(name: string) {
    |     this.name = name;
     @ multi (webpack)-dev-server/client?http://localhost:9000 ./src/index.ts main[1]
    Child html-webpack-plugin for "index.html":
         1 asset
        Entrypoint undefined = index.html
        [./node_modules/html-webpack-plugin/lib/loader.js!./index.html] 409 bytes {0} [built]
        [./node_modules/lodash/lodash.js] 527 KiB {0} [built]
        [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 506 bytes {0} [built]
        [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 669 bytes {0} [built]
     wdm: Failed to compile.
Mar.10,2022

ts file needs to specify loader to parse

{
    test: /\.ts?$/,
    loader: 'ts-loader'
}
Menu