Karma-typescript cannot find module "readable-stream/duplex.js"

684 Views Asked by At

The closest thing I have found here is karma-typescript cannot find module but that one refers to an issue where karma-typescript cannot find a source file not a dependency. Its solution didn't work anyway.

I am trying to set up unit testing for a TypeScript project using Karma, Mocha, and Chai. I decided to use the karma-typescript package in npm to set up my tests so they didn't have to compile to Javascript first. When I run 'karma start karma.conf.js' it runs for a bit, then returns:

02 03 2019 14:08:28.791:DEBUG [coverage.karma-typescript]: Initializing
02 03 2019 14:08:28.799:DEBUG [compiler.karma-typescript]: Setting up deferred project compilation
02 03 2019 14:08:28.800:DEBUG [coverage.karma-typescript]: Configuring coverage preprocessor
02 03 2019 14:08:28.805:ERROR [karma-server]: Server start failed on port 9876: Error: Cannot find module 'readable-stream/duplex.js'
npm ERR! Test failed.  See above for more details.

I have tried manually adding readable-stream, even though readable-stream is in karma-typescript's package.json, but it does not seem to do anything different. I have set up karma.conf.js as so:

const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath();

module.exports = function(config) {
config.set({

basePath: '',

frameworks: ['mocha', 'chai', 'karma-typescript'],

karmaTypescriptConfig: {
  compilerOptions: {
    module: "commonjs"
  },
  tsconfig: "./src/ts/tsconfig.json"
},

files: [
  'src/**/*.ts'
],

exclude: [
],

preprocessors: {
  "**/*.ts": ["karma-typescript"]
},

reporters: ['progress', 'karma-typescript'],

port: 9876,

colors: true,

// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,

autoWatch: false,

browsers: ['ChromeHeadless'],

singleRun: true,

concurrency: Infinity
})
}

My tsconfig.json looks like this and is stored in the same folder as all the .ts source files (src/ts/):

{
   "compilerOptions": {
   "target": "es2018",
   "outDir": "../js",
   "rootDir": "./",
   "strict": true,
   "moduleResolution": "node",
   "esModuleInterop": true
   }
}
0

There are 0 best solutions below