karma-sourcemap-loader

raw JSON →
0.4.0 verified Sat Apr 25 auth: no javascript

A Karma plugin preprocessor that loads existing JavaScript source map files (both inline and external) into the Karma test runner. Version 0.4.0 is current stable. Unlike karma-sourcemap-preprocessor, this plugin does not generate source maps but locates them from previous build steps (e.g., TypeScript, Babel, webpack). It supports remapping source paths via prefix replacement or custom callback, and modifying sourceRoot. Inline source maps using base64 are also supported. Release cadence is low, primarily maintenance updates. Key differentiator: solves source map loading when compilation happens outside Karma.

error Error: No provider for "sourcemap"! (Resolving: sourcemap)
cause Preprocessor name 'sourcemap' is misspelled or not configured correctly.
fix
Ensure preprocessors config uses 'sourcemap' exactly, e.g., preprocessors: { '**/*.js': ['sourcemap'] }.
error ReferenceError: module is not defined in ES module scope
cause Using CommonJS module.exports in an ESM project (package.json type: module).
fix
Rename file to .cjs or use export default or dynamic import() for ES modules.
gotcha Preprocessor name is 'sourcemap' not 'karma-sourcemap-loader'.
fix Use 'sourcemap' as the preprocessor name in preprocessors config.
gotcha Configuration key is 'sourceMapLoader' (camelCase) not 'sourcemaploader' or 'source-map-loader'.
fix Use 'sourceMapLoader' in config.set().
breaking Removed Node.js < 10 support. Graceful-fs usage may break on older Node.
fix Upgrade Node.js to version 10 or later.
deprecated The 'remapSource' callback function may be deprecated in future versions; prefer 'remapPrefixes'.
fix Use 'remapPrefixes' object instead of 'remapSource' function if possible.
npm install karma-sourcemap-loader
yarn add karma-sourcemap-loader
pnpm add karma-sourcemap-loader

Configures Karma to load existing source maps for all JS files, remapping paths with a prefix.

// karma.conf.js
module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: ['src/**/*.js', 'test/**/*.spec.js'],
    preprocessors: {
      '**/*.js': ['sourcemap']
    },
    sourceMapLoader: {
      remapPrefixes: {
        '/myproject/': '../src/'
      }
    },
    browsers: ['ChromeHeadless'],
    singleRun: true
  });
};