Skip to content

ngcc: Duplicate export 'HttpClientXsrfModule' in fesm5/http.js #28068

Closed

Description

@cexbrayat

🐞 bug report

Affected Package

The issue is caused by package @angular/common/http

Last line of ./node_modules/@angular/common/fesm5/http.js looks like:

export { ..., HttpClientJsonpModule, HttpClientModule, HttpClientXsrfModule, ... };

After running ngcc, a new line appears just below:

export {HttpClientXsrfModule};

Which then makes ng build --aot fail (if HttpClientModule is imported), with or without ivy enabled with:

ERROR in ./node_modules/@angular/common/fesm5/http.js 2024:9
Module parse failed: Duplicate export 'HttpClientXsrfModule' (2024:9)
You may need an appropriate loader to handle this file type.
|  */
| export { NoopInterceptor as ɵangular_packages_common_http_http_a, JsonpCallbackContext as ɵangular_packages_common_http_http_b, jsonpCallbackContext as ɵangular_packages_common_http_http_c, BrowserXhr as ɵangular_packages_common_http_http_d, HttpXsrfCookieExtractor as ɵangular_packages_common_http_http_g, HttpXsrfInterceptor as ɵangular_packages_common_http_http_h, XSRF_COOKIE_NAME as ɵangular_packages_common_http_http_e, XSRF_HEADER_NAME as ɵangular_packages_common_http_http_f, HttpBackend, HttpHandler, HttpClient, HttpHeaders, HTTP_INTERCEPTORS, JsonpClientBackend, JsonpInterceptor, HttpClientJsonpModule, HttpClientModule, HttpClientXsrfModule, HttpInterceptingHandler as ɵHttpInterceptingHandler, HttpParams, HttpUrlEncodingCodec, HttpRequest, HttpErrorResponse, HttpEventType, HttpHeaderResponse, HttpResponse, HttpResponseBase, HttpXhrBackend, XhrFactory, HttpXsrfTokenExtractor };
> export { HttpClientXsrfModule };

Is this a regression?

The bug has been present since 7.0 releases (talked on Slack with @petebacondarwin ).

Description

ngcc exports HttpClientXsrfModule twice.

🔬 Minimal Reproduction

ng new ivy-http --defaults
cd ivy-http
$(npm bin)/ivy-ngcc
# check ./node_modules/@angular/common/fesm5/http.js
# add HttpClientModule to AppModule
ng build --aot

🔥 Exception or Error


ERROR in ./node_modules/@angular/common/fesm5/http.js 2024:9
Module parse failed: Duplicate export 'HttpClientXsrfModule' (2024:9)
You may need an appropriate loader to handle this file type.
|  */
| export { NoopInterceptor as ɵangular_packages_common_http_http_a, JsonpCallbackContext as ɵangular_packages_common_http_http_b, jsonpCallbackContext as ɵangular_packages_common_http_http_c, BrowserXhr as ɵangular_packages_common_http_http_d, HttpXsrfCookieExtractor as ɵangular_packages_common_http_http_g, HttpXsrfInterceptor as ɵangular_packages_common_http_http_h, XSRF_COOKIE_NAME as ɵangular_packages_common_http_http_e, XSRF_HEADER_NAME as ɵangular_packages_common_http_http_f, HttpBackend, HttpHandler, HttpClient, HttpHeaders, HTTP_INTERCEPTORS, JsonpClientBackend, JsonpInterceptor, HttpClientJsonpModule, HttpClientModule, HttpClientXsrfModule, HttpInterceptingHandler as ɵHttpInterceptingHandler, HttpParams, HttpUrlEncodingCodec, HttpRequest, HttpErrorResponse, HttpEventType, HttpHeaderResponse, HttpResponse, HttpResponseBase, HttpXhrBackend, XhrFactory, HttpXsrfTokenExtractor };
> export { HttpClientXsrfModule };

🌍 Your Environment

Angular Version:


Angular CLI: 7.2.0
Node: 10.14.1
OS: darwin x64
Angular: 7.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.0
@angular-devkit/build-angular     0.12.0
@angular-devkit/build-optimizer   0.12.0
@angular-devkit/build-webpack     0.12.0
@angular-devkit/core              7.2.0
@angular-devkit/schematics        7.2.0
@ngtools/webpack                  7.2.0
@schematics/angular               7.2.0
@schematics/update                0.12.0
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.23.1

Activity

  1. petebacondarwin commented on Jan 11, 2019

    @petebacondarwin
    Contributor

    We are not checking in ngcc to see whether an export that we need is already exported in the code...

  2. added this to the Backlog milestone on Jan 11, 2019
  3. JoostK commented on Jan 24, 2019

    @JoostK
    Member

    I can no longer reproduce. AFAIK, only ngcc's PrivateDeclarationsAnalyzer contributes to the exports that are written into the output, which does take into account a module's exports. I'm not sure which of the recent changes has apparently resolved this issue though.

  4. petebacondarwin commented on Jan 25, 2019

    @petebacondarwin
    Contributor

    I don't see it in the latest ngcc of @angular/common either.
    @cexbrayat - can you double check this before I close it?

  5. gkalpak commented on Jan 25, 2019

    @gkalpak
    Member

    This is the error I was fixing with 78da65f23 (part of #26947). The problem was that (for some reason I don't recall 😇), ngcc would be requested to find the declaration of both the outer HttpClientXsrfModule variable identifier and the inner (from inside the IIFE) HttpClientXsrfModule function identifier. (Error on CI).

    var HttpClientXsrfModule = (function () {
        function HttpClientXsrfModule() {
        }
        return HttpClientXsrfModule;
    }());

    Since it could not detect that both identifier refer to the same thing (and return the same declaration), it would create an extra import for essentially the same thing.

    Not sure why it works now without my fix 😁

  6. gkalpak commented on Jan 25, 2019

    @gkalpak
    Member

    (To be clear: I tried building aio with ivy without my fix and I no longer get the Duplicate export error I was getting before.)

  7. JoostK commented on Jan 25, 2019

    @JoostK
    Member

    I suspected #27848 to have something to do with it, but I tried reverting that change and this issue did still not occur. I don't know what happened 🤷‍♂️

  8. cexbrayat commented on Jan 25, 2019

    @cexbrayat
    MemberAuthor

    I tried again, and the problem is indeed fixed with 8.0.0-beta.1 👍

  9. CarreraPHP commented on Mar 6, 2019

    @CarreraPHP

    Below is my Angular Client Version Details & My application is created with experimental-ivy config.
    I am still facing the issue, can i know in version of 7.x.x the fix will be available?

    image

    image

  10. petebacondarwin commented on Mar 6, 2019

    @petebacondarwin
    Contributor

    This will not be fixed in Angular 7.x, since ngcc is a tool in the new ivy feature set which is not part of v7.

  11. CarreraPHP commented on Mar 10, 2019

    @CarreraPHP

    @petebacondarwin, thanks for the reply. I am now having 2 applications with same code base. One normal & other ivy. Let me try with the 8.x Version and report if any issue faced.

  12. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    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.

  13. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions