Webpack worker-loader + karma = Error


#1

Im trying to add Worker Loader in Ionic project. I am able to run the app but failed at running karma!

Added webpack worker-loader to project how discribe here https://webpack.js.org/loaders/worker-loader/#integrating-with-typescript

  1. Install worker-loader - npm i -D worker-loader
  2. Created worker typescript file src/…/worker/bootstrap.worker.ts
  3. Created worker type definitions in src/typings.d.ts

"ionic serve" or "ionic build --prod" - OK
"npm run test" - "ERROR in ./node_modules/@ngtools/webpack/src!./src/…/bootstrap.worker.ts
_ Module build failed: Error: @ngtools/webpack is being used as a loader but no tsConfigPath option nor AotPlugin was detected. You must provide at least one of these._
_ at Object.ngcLoader (C:…\node_modules@ngtools\webpack\src\loader.js:617:19)"_

How make correct config for karma?


#2

I added “module” section to “webpack” section in karma.conf.js

webpack: { 
  node: { 
    fs: 'empty' 
  },
  module: {
    rules: [
        {
          test: /\.ts$/,
          loader: "@ngtools/webpack",
          options: {
            tsConfigPath: "./src/tsconfig.spec.json",
          }
        },
        { test: /\.css$/, use: 'css-loader' },
        { test: /\.html$/, use: 'html-loader' },
        { test: /\.svg$/, use: 'html-loader' }
    ]
  }
}

After this “npm run test” works!