Angular Unit Test - Cannot find module “tslib”

Angular Unit Test - Cannot find module “tslib”

When running angular UT, you may encounter the error message looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Uncaught Error: Cannot find module 'tslib'
at webpackEmptyContext (src sync:2) [<root>]
at :9876/_karma_webpack_/d:/workspace/web/node_modules/@angular/compiler/src/core.js:19:1 [<root>]
at :9876/_karma_webpack_/d:/workspace/web/node_modules/@angular/compiler/src/core.js:10:1 [<root>]
at Object.../../node_modules/@angular/compiler/src/core.js
(:9876/_karma_webpack_/d:/workspace/web/node_modules/@angular/compiler/src/core.js:16) [<root>]
at __webpack_require__ (bootstrap:79) [<root>]
at Module../src/lib/service/service.spec.ts (xx.service.ts:36) [<root>]
at __webpack_require__ (bootstrap:79) [<root>]
at webpackContext (src sync \.spec\.ts$:22) [<root>]
at Array.map (<anonymous>) [<root>]
at Module../src/test.ts (test.ts:23) [<root>]
at __webpack_require__ (bootstrap:79) [<root>]
at checkDeferredModules (bootstrap:45) [<root>]
at :9876/_karma_webpack_/webpack/bootstrap:152:1 [<root>]
at :9876/_karma_webpack_/main.js:156:10 [<root>]

This should be coming from Angular Core

removed:

1
import { Type } from '@angular/compiler/src/core';

Using:

1
import { Injectable, Type } from '@angular/core';