Skip to content

dedupe-duplicate-modules turn on/off option request #17967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eun-choi opened this issue Jun 19, 2020 · 6 comments · Fixed by #18009
Closed

dedupe-duplicate-modules turn on/off option request #17967

eun-choi opened this issue Jun 19, 2020 · 6 comments · Fixed by #18009

Comments

@eun-choi
Copy link

eun-choi commented Jun 19, 2020

🚀 Feature request

I would like to the option to turn on/off the 'dedupe-duplicate-modules' function at build time.

Because, I'm using both the DateAdapter module of '@angular/material/core' and the DateAdapter module of 'angular-calendar'.

Therefore, either of them will not work after build that due to the 'dedupe-duplicate-modules' function.

Sample code
a.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material/core';
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    RouterModule.forChild(routes),
    ReactiveFormsModule,
    MatFormFieldModule,
    MatInputModule,
    MatDatepickerModule,
    MatNativeDateModule,
    NgxMaterialTimepickerModule,
  ],

a.component.ts

import { MatDatepickerInputEvent, MatDatepicker } from '@angular/material/datepicker';
import { MAT_MOMENT_DATE_FORMATS, MomentDateAdapter, MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import { NgxMaterialTimepickerComponent, NgxMaterialTimepickerTheme } from 'ngx-material-timepicker';
@Component({
  providers: [
    { provide: MAT_DATE_LOCALE, useValue: 'en-US' },
    { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS] },
    { provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS }
  ]
})

b.module.ts

import { NgModule } from '@angular/core';
import { CommonModule, registerLocaleData } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { CalendarModule, DateAdapter } from 'angular-calendar';
import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    CalendarModule.forRoot({provide: DateAdapter, useFactory: adapterFactory}),
    RouterModule.forChild(routes),

b.component.ts

import { CalendarEvent, CalendarView, DAYS_OF_WEEK, CalendarMonthViewDay, CalendarDateFormatter, CalendarEventTitleFormatter } from 'angular-calendar';
import { isSameMonth, isSameDay } from 'date-fns';
import { CustomDateFormatter } from './custom-date-formatter.provider';
import { CustomEventTitleFormatter } from './custom-title-formatter.provider';
@Component({
  providers: [
    {
      provide: CalendarDateFormatter,
      useClass: CustomDateFormatter
    },
    {
      provide: CalendarEventTitleFormatter,
      useClass: CustomEventTitleFormatter
    }
  ]
})

It works fine until @angular-devkit/build-angular@0.1000.0-next.6

But, An error occurs from @angular-devkit/build-angular@0.1000.0-rc.0 or later.

error log

core.js:4073 ERROR Error: Cannot instantiate cyclic dependency! DateAdapter
    at throwCyclicDependencyError (core.js:5357)
    at R3Injector.hydrate (core.js:11262)
    at R3Injector.get (core.js:11088)
    at NgModuleRef$1.get (core.js:23982)
    at Object.get (core.js:22238)
    at getOrCreateInjectable (core.js:3799)
    at ɵɵdirectiveInject (core.js:13770)
    at ɵɵinject (core.js:804)
    at NodeInjectorFactory.CustomDateFormatter_Factory [as factory] (ɵfac.js? [sm]:1)
    at getNodeInjectable (core.js:3907)

Therefore, it seems to be affected by the 'dedupe-duplicate-modules' function.

@alan-agius4
Copy link
Collaborator

Hi @eun-choi,

The dedupe-duplicate-modules only dedupes modules with the same name and versions and not symbols.

You can get which modules are being deduped by adding the following two options --no-progress --verbose in the command line when running ng build/serve.

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

To continue looking at this we'd require a minimal reproduction. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

@alan-agius4 alan-agius4 added needs: repro steps We cannot reproduce the issue with the information given area: @angular-devkit/build-angular labels Jun 19, 2020
@ngbot ngbot bot added this to the needsTriage milestone Jun 19, 2020
@eun-choi
Copy link
Author

Currently, I had installed @angular-devkit/build-angular@0.1000.0-rc.5 version.
And then, If I comment out as below, APP works fine.

node_modules > @Angular-devkit > build-angular > src > angular-cli-files > models > webpack-configs > common.js in line 382

            plugins: [
                PnpWebpackPlugin,
                // new webpack_2.DedupeModuleResolvePlugin({ verbose: buildOptions.verbose }),
            ],

First, I'll try to find if it can be solved by any method other than comment out.

@alan-agius4
Copy link
Collaborator

@eun-choi, unfortunately without a reproduction we'll be unable to look and solve the issue.

@eun-choi
Copy link
Author

eun-choi commented Jun 23, 2020

[minimal reproduction code]
https://github.com/eun-choi/dedupe-test

[environment]

  "dependencies": {
    "@angular/animations": "^10.0.0-rc.6",
    "@angular/cdk": "^10.0.0-rc.3",
    "@angular/common": "^10.0.0-rc.6",
    "@angular/core": "^10.0.0-rc.6",
    "@angular/forms": "^10.0.0-rc.6",
    "@angular/material": "^10.0.0-rc.3",
    "@angular/material-moment-adapter": "^10.0.0-rc.3",
    "@angular/platform-browser": "^10.0.0-rc.6",
    "@angular/platform-browser-dynamic": "^10.0.0-rc.6",
    "@angular/router": "^10.0.0-rc.6",
    "@ionic/angular": "^5.2.2",
    "angular-calendar": "^0.28.16",
    "date-fns": "^2.14.0",
    "moment": "^2.27.0",
    "rxjs": "^6.5.5",
    "tslib": "^2.0.0",
    "zone.js": "^0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1000.0-rc.5",
    "@angular/cli": "^10.0.0-rc.5",
    "@angular/compiler": "^10.0.0-rc.6",
    "@angular/compiler-cli": "^10.0.0-rc.6",
    "@angular/language-service": "^10.0.0-rc.6",
    "@ionic/angular-toolkit": "^2.2.0",
    "@types/node": "^14.0.13",
    "codelyzer": "^5.2.2",
    "ts-node": "^8.10.2",
    "tslint": "^6.1.2",
    "typescript": "^3.9.5"
  },

[System]
NodeJS : v12.18.0
npm : 6.14.5
OS : macOS Catalina


@alan-agius4

  1. clone git url: https://github.com/eun-choi/dedupe-test
  2. npm i
  3. ng serve
  4. 'tab1' work fine. but, 'tab2' error occur.
  5. npm i @angular-devkit/build-angular@0.1000.0-next.6
  6. ng serve
  7. both 'tab1' and 'tab2' works fine.

@alan-agius4
Copy link
Collaborator

The problem seems to be caused because angular-calendar is shipping date-fns as part of their distributable, however this doesn't have a name nor a version which is causing incorrect dedupping.

We should handle such cases and don't dedupe a module when we don't have a name or version in the manifest.

@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jun 24, 2020
@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely and removed freq2: medium labels Jun 24, 2020
filipesilva pushed a commit that referenced this issue Jun 29, 2020
…me or version

We should not try to dedupe secondary entrypoints, or modules which don't have a name and a version.

Closes #17967
filipesilva pushed a commit that referenced this issue Jun 29, 2020
…me or version

We should not try to dedupe secondary entrypoints, or modules which don't have a name and a version.

Closes #17967
villelahdenvuo pushed a commit to villelahdenvuo/angular-cli that referenced this issue Jul 6, 2020
…me or version

We should not try to dedupe secondary entrypoints, or modules which don't have a name and a version.

Closes angular#17967
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants