Karma Webpack 5 在阅读打字稿时抛出“模块解析失败”

问题描述

我在 Angular 11 和 Webpack 4 上正确运行了 Karma + Jasmine 测试。但是,当尝试将 Angular 和 Webpack 更新到 v12 和 v5 时,我在启动测试时遇到了以下错误

enter image description here

这是我的 Karma 配置:

    module.exports = (config) => {
  config.set({
    // ... normal karma configuration

    // make sure to include webpack as a framework
    frameworks: ['jasmine','webpack'],plugins: [
      'karma-webpack','karma-jasmine','karma-chrome-launcher','karma-jasmine-html-reporter','karma-coverage-istanbul-reporter','karma-sourcemap-loader',],files: [
      // all files ending in ".spec.ts"
      // !!! use watched: false as we use webpacks watch
      { pattern: './src/test.ts',watched: false }
    ],preprocessors: {
      // add webpack as preprocessor
      './src/test.ts': ['webpack','sourcemap']
    },browsers: ['Chrome'],reporters: ['progress'],port: 9876,webpack: require('./webpack-test.config')
  });
}

还有我的 Webpack 配置:

const singleSpaAngularWebpack = require('single-spa-angular/lib/webpack').default
const path = require('path');

module.exports = (angularWebpackConfig,options) => {
  const singleSpaWebpackConfig = singleSpaAngularWebpack(angularWebpackConfig,options);
    
  singleSpaWebpackConfig.externals = [
    /^@example\/*/,];

  singleSpaWebpackConfig.module.rules.add({ test: /\.spec\.tsx$/,use: ['ts-loader','angular2-template-loader'] })

  return singleSpaWebpackConfig
}

我也尝试过我之前使用的自定义规则,但遇到了同样的错误

先谢谢你!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)