Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency on 'hammerjs'. CommonJS or AMD dependencies can cause optimization bailouts

I am working on an angular application with Angular CLI 11.0.2 and I am using hammerJS in my application to handle the swipe events.

When I compile the application, I have the following warning message:

Warning: F:\Programs\GoodRiddles\git\angular\src\app\config\hammerjs.config.ts depends on 'hammerjs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

From what I could understand here, I should replace hammerJS by an ECMA version of the library.

My question is: Is there a proper way (without simply hiding the message) to fix it? Do I need to use another library instead?

If it can help, this is how I use it:

import { Injectable } from '@angular/core';
import { HammerGestureConfig } from "@angular/platform-browser";
import * as hammer from "hammerjs";

@Injectable()
export class HammerConfig extends HammerGestureConfig {
    overrides = <any>{
        swipe: { direction: hammer.DIRECTION_HORIZONTAL },
        pinch: { enable: false },
        rotate: { enable: false }
    };
}
like image 446
J.F. Avatar asked Nov 21 '20 22:11

J.F.


1 Answers

Add Hammerjs to allowedCommonJsDependencies in your angular.json

"architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "allowedCommonJsDependencies": [
          "hammerjs" <== here
        ],...
like image 96
Tarek Elmadady Avatar answered Nov 02 '22 14:11

Tarek Elmadady