xml2js in Angular 6: Can't resolve 'stream' and 'timers'

You’ll have to install those dependencies. It’s unfortunately not well documented.

npm install --save stream timers

For Angular to recognise xml2js, the following steps are required:

  1. Add the timers-browserify node module using "npm install timers-browserify"
  2. Add the stream-browserify node module using "npm install stream-browserify"
  3. Add the following path mapping in your tsconfig.json:
    "compilerOptions": {
      "paths": {
        "timers": [
          "node_modules/timers-browserify"
        ],
        "stream": [
          "node_modules/stream-browserify"
        ],
      }
    }