0

While trying to run my project ionic cordova run Android it will show error:-

[13:07:43]  typescript error 
            Cannot find type definition file for 'hammerjs'. 

TypeError: Cannot read property 'replace' of null
    at Object.escapeHtml (D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\util\helpers.js:253:10)
    at generateCodeBlock (D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\logger\logger-diagnostics.js:187:77)
    at generateDiagnosticHtml (D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\logger\logger-diagnostics.js:179:12)
    at Array.map (<anonymous>)
    at Object.printDiagnostics (D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\logger\logger-diagnostics.js:15:39)
    at D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\transpile.js:158:34
    at new Promise (<anonymous>)
    at transpileWorker (D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\transpile.js:107:12)
    at Object.transpile (D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\transpile.js:64:12)
    at D:\projects\hafele_latest\node_modules\@ionic\app-scripts\dist\build.js:109:82

I already added @types/hammerjs. I dont think it's a definition error. I think it is app-script error.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614

2 Answers2

1

Check if hammerjs is properly installed or not, in my case just running the following command resolved the issue

npm i @types/hammerjs
Rahul_Mandhane
  • 187
  • 1
  • 11
  • What is the explanation for this? What are @types/* and why are they needed? – Ade Sep 23 '22 at 16:43
  • 1
    @Ade. you can refer this https://stackoverflow.com/questions/37548066/typescript-typings-in-npm-types-org-packages and the command npm i @types/hammerjs is to install hammerjs – Rahul_Mandhane Dec 10 '22 at 14:36
0

Something like this happened to me and the issue was I didn't have

import 'hammerjs' ;

in my main.js file. Also, I use

import { BrowserModule, HammerModule } from '@angular/platform-browser';

in my component.ts

Kinglish
  • 23,358
  • 3
  • 22
  • 43