angularangular2-cli

Module not found: Error: Can't resolve 'hammerjs'


I updated my Angular 2 CLI project from 1.0.0-beta.11-webpack.2 to 1.0.0-beta.11-webpack.8 via ng init. My project uses Angular 2.0.0-rc.5 and Angular Material 2.0.0-alpha.7-4 but when run with ng serve I get the following error:

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve 'hammerjs' in '/home/jan/src/fm-repos/fm-ui/src/app'
 @ ./src/app/app.module.ts 38:0-18
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

ERROR in [default] /home/jan/src/fm-repos/fm-ui/node_modules/@angular2-material/core/gestures/MdGestureConfig.d.ts:4:39 
Cannot find name 'HammerManager'.

ERROR in [default] /home/jan/src/fm-repos/fm-ui/node_modules/@angular2-material/slide-toggle/slide-toggle.d.ts:67:19 
Cannot find name 'HammerInput'.

ERROR in [default] /home/jan/src/fm-repos/fm-ui/node_modules/@angular2-material/slider/slider.d.ts:50:19 
Cannot find name 'HammerInput'.

ERROR in [default] /home/jan/src/fm-repos/fm-ui/node_modules/@angular2-material/slider/slider.d.ts:52:24 
Cannot find name 'HammerInput'.

Solution

  • To work-around this bug, temporarily add hammerjs to your project:

    npm install hammerjs --save
    npm install @types/hammerjs --save-dev
    

    and import in your module definition:

    /** TODO: remove when work-around is not needed*/
    import 'hammerjs';
    
    
    @NgModule({
      declarations: [
        AppComponent,
        HeaderComponent,
        // ...