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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 05:30:48

问题


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'.

回答1:


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,
    // ...



回答2:


I was facing issue

npm uninstall hammerjs --save

then npm install hammerjs@latest

solved my problem

hammerjs latest installed version is 2.0.8 Angular is 5.2.11



来源:https://stackoverflow.com/questions/39496267/module-not-found-error-cant-resolve-hammerjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!