{"id":25831,"library":"karma-typescript-preprocessor2","title":"Karma TypeScript Preprocessor 2","description":"A Karma preprocessor plugin that transpiles TypeScript files using the gulp-typescript compiler with incremental compilation for fast rebuilds. Version 1.2.1 is the latest stable release. It relies on tsconfig.json for primary configuration, supports custom compiler overrides, sourcemaps via gulp-sourcemaps, and virtual path transformations. Notable features include very fast incremental rebuilds, good error reporting, and the ability to exclude .d.ts files. However, it has several unsupported TypeScript config options (sourceMap, rootDir, watch, project) and may face compatibility issues with newer Karma or TypeScript versions.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/klaygomes/karma-typescript-preprocessor2","tags":["javascript","karma","karma-plugin","karma-typescript","karma-typescript-preprocessor"],"install":[{"cmd":"npm install karma-typescript-preprocessor2","lang":"bash","label":"npm"},{"cmd":"yarn add karma-typescript-preprocessor2","lang":"bash","label":"yarn"},{"cmd":"pnpm add karma-typescript-preprocessor2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core transpiler dependency","package":"gulp-typescript","optional":false},{"reason":"Required for generating sourcemaps","package":"gulp-sourcemaps","optional":true}],"imports":[{"note":"This is a Karma plugin, not imported in code. It is loaded by Karma when listed in preprocessors.","wrong":"npm install karma-typescript-preprocessor (without 2)","symbol":"default","correct":"// Add 'typescript' to karma preprocessors list in karma.conf.js"},{"note":"Configuration is placed in karma.conf.js under 'typescriptPreprocessor' key.","wrong":"config.set({ preprocessor: { ... } })","symbol":"typescriptPreprocessor config","correct":"config.set({ typescriptPreprocessor: { ... } })"},{"note":"transformPath is an array of functions inside typescriptPreprocessor.","wrong":"config.set({ transformPath: ... })","symbol":"transformPath","correct":"config.set({ typescriptPreprocessor: { transformPath: [function(path){ ... }] } })"}],"quickstart":{"code":"// karma.conf.js\nmodule.exports = function(config) {\n  config.set({\n    basePath: '',\n    frameworks: ['jasmine'],\n    files: [\n      'src/**/*.ts',\n      'test/**/*.spec.ts'\n    ],\n    preprocessors: {\n      '**/*.ts': ['typescript', 'sourcemap']\n    },\n    typescriptPreprocessor: {\n      tsconfigPath: './tsconfig.json',\n      compilerOptions: {\n        module: 'commonjs',\n        target: 'es5'\n      },\n      sourcemapOptions: {\n        includeContent: true,\n        sourceRoot: '/src'\n      },\n      transformPath: [function(path) {\n        return path.replace(/\\.ts$/, '.js');\n      }]\n    },\n    reporters: ['progress'],\n    port: 9876,\n    colors: true,\n    logLevel: config.LOG_INFO,\n    autoWatch: true,\n    browsers: ['ChromeHeadless'],\n    singleRun: false\n  });\n};","lang":"javascript","description":"Configures Karma to preprocess TypeScript files with this plugin. Includes tsconfig.json reference, sourcemap generation, and path transformation."},"warnings":[{"fix":"Use compilerOptions in typescriptPreprocessor to override, but avoid those keys. Use gulp.src base option instead of rootDir. Set singleRun: false for watch.","message":"Unsupported TypeScript config options: sourceMap, inlineSources, sourceRoot, rootDir, watch, project","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure tsconfig.json exists and path is correct relative to Karma basePath.","message":"The tsconfigPath option is obligatory; without it the plugin will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always include a transform that changes .ts to .js in your transformPath array.","message":"transformPath default replaces .ts with .js; if you override, you must include that transformation or files won't be served.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need different TypeScript features, use karma-typescript or karma-webpack instead.","message":"Plugin only works with gulp-typescript; it does not use the official TypeScript compiler API.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install karma-typescript-preprocessor2 --save-dev` and ensure preprocessors config has 'typescript'.","cause":"Plugin not installed or not listed in karma.conf.js preprocessors.","error":"Error: Preprocessor 'typescript' is not registered! (or similar)"},{"fix":"Add `typescriptPreprocessor: { tsconfigPath: './tsconfig.json' }` to config.set().","cause":"typescriptPreprocessor config block missing in karma.conf.js.","error":"TypeError: Cannot read property 'tsconfigPath' of undefined"},{"fix":"Run `npm install gulp-typescript --save-dev`.","cause":"gulp-typescript peer dependency missing.","error":"Unhandled rejection: Error: Could not find any TypeScript compiler. Did you install gulp-typescript?"},{"fix":"Ensure transformPath is an array of functions, e.g., `transformPath: [function(path) { return path.replace(/\\.ts$/, '.js'); }]`.","cause":"transformPath item is not a function or array.","error":"TypeError: path.replace is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}