Skip to content

Angular 8 -> Angular 9 breaks with mydatepicker #32729

Closed

Description

@whyboris

🐞 bug report

Affected Package

mydatepicker https://github.com/kekeh/mydatepicker

Is this a regression?

Angular 8.2.6 works
Angular 9.0.0-next.5 fails

Description

Everything works as expected with 8.2.6
Upgrading to 9.0.0-next.5 fails to build (Ivy disabled, aot enabled)

🔬 Minimal Reproduction

https://github.com/whyboris/angular-ivy-problem
I created a new app (npm install -g @angular/cli@latest & ng new angular-ivy-problem)
The repository contains that code (no changes) along with two branches:
branch 1 named ERROR follows the minimal requirements to get mydatepicker working. The code change is in this PR: https://github.com/whyboris/angular-ivy-problem/pull/1
branch 2 named no-error which simply downgrades the angular & cli versions to latest version 8 is in this PR: https://github.com/whyboris/angular-ivy-problem/pull/2/files (note it's a PR against ERROR

🔥 Exception or Error


ERROR in node_modules/mydatepicker/dist/my-date-picker.module.d.ts:1:22 - error TS-996002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class

1 export declare class MyDatePickerModule {
                       ~~~~~~~~~~~~~~~~~~
src/app/app.component.html:5:3 - error TS8001: 'my-date-picker' is not a valid HTML element.

5   
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  src/app/app.component.ts:7:16
    7   templateUrl: './app.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component AppComponent.
src/app/app.component.html:5:33 - error TS8002: 'options' is not a valid property of .

5   
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  src/app/app.component.ts:7:16
    7   templateUrl: './app.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component AppComponent.
src/app/app.component.html:5:65 - error TS8002: 'ngModel' is not a valid property of .

5   
                                                                  ~~~~~~~~~~~~~~~~~~~

  src/app/app.component.ts:7:16
    7   templateUrl: './app.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component AppComponent.
src/app/app.component.html:8:1 - error TS8001: 'router-outlet' is not a valid HTML element.

8 
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  src/app/app.component.ts:7:16
    7   templateUrl: './app.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component AppComponent.

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.0-next.4
Node: 12.10.0
OS: darwin x64
Angular: 9.0.0-next.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-next.4
@angular-devkit/build-angular     0.900.0-next.4
@angular-devkit/build-optimizer   0.900.0-next.4
@angular-devkit/build-webpack     0.900.0-next.4
@angular-devkit/core              9.0.0-next.4
@angular-devkit/schematics        9.0.0-next.4
@angular/cli                      9.0.0-next.4
@ngtools/webpack                  9.0.0-next.4
@schematics/angular               9.0.0-next.4
@schematics/update                0.900.0-next.4
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.3

Anything else relevant?
Also very related to errors encountered in #32466

Activity

  1. compeek commented on Sep 17, 2019

    @compeek

    I had a lot of these kinds of errors trying to get my project working with Angular 9 and Ivy. I could not pinpoint the exact cause, the the combination of these two things seemed to resolved them for the most part:

    1. Add "allowEmptyCodegenFiles": true to the "angularCompilerOptions" block in tsconfig.json
    2. Add this npm script: "postinstall": "ivy-ngcc" to package.json and then delete node_modules completely and rerun npm install (which will run the postinstall script automatically)

    I would recommend you try each of those and see if it gives you any better results.

    I'm not using mydatepicker, but I suspect your problems aren't specific to mydatepicker. My experience with Ivy so far in the last few days unfortunately has been that it's still very finicky, especially with third party libraries and/or lazy loaded modules (not sure which is the exact cause).

    In particular with suggestion 2 above, even though the compiler automatically runs the ngcc compiler now (from what I gather, anyway), it doesn't seem to do it properly because I get better results running it manually first with that npm script.

  2. added this to the needsTriage milestone on Sep 17, 2019
  3. whyboris commented on Sep 18, 2019

    @whyboris
    Author

    Thank you @compeek -- I added allowEmptyCodeGenFiles, postinstall, removed node_modules and ran npm install again. Unfortunately in my case I still get the above errors.

    I suspect what you recommend makes a difference, but perhaps I should just move on from mydatepicker (latest versions 2.6.6, last updated 1 year ago) to angular-mydatepicker, its successor 🤷‍♂

    Either way it may be worth for the Angular team to investigate why a simple version upgrade breaks things (even without turning Ivy on) 😕

  4. whyboris commented on Sep 18, 2019

    @whyboris
    Author

    For reference, I created a branch new-datepicker using angular-mydatepicker library instead of mydatepicker -- the PR for it: https://github.com/whyboris/angular-ivy-problem/pull/3
    It works with Angular 9 (current latest 9.0.0-next.5) 🎉 even with Ivy enabled 🎉 🎉

  5. JoostK commented on Sep 26, 2019

    @JoostK
    Member

    Finally found some time to look into this. The mydatepicker lib is not processed by itself as its library structure follows an unusual layout, where index.js/index.d.ts files are at the root, but Angular's metadata file is stored at dist/index.metadata.json. ngcc needs some hint to know this is indeed an Angular package that needs to be processed, which can be accomplished by creating a ngcc.config.js (that's .js, not .json!) file in the root of the project (next to the root package.json):

    module.exports = {
      packages: {
        'mydatepicker': {
          entryPoints: {
            '.': {}
          }
        },
      },
    };

    This is enough to teach ngcc that mydatepicker needs to be processed as an Angular library. With this config, the library is processed correctly and the app compiles successfully.

    Unfortunately, the app will fail at runtime:

    NullInjectorError: R3InjectorError(AppModule)[Renderer -> Renderer -> Renderer]: 
      NullInjectorError: No provider for Renderer!
    

    The Renderer API has been deprecated a long time ago and is no longer available in Ivy, so the library is just no longer compatible.

    The error that is being reported is less than ideal, as it doesn't really tell why it's failing nor what can be done to rectify the issue. If you have suggestions for improving the situation, please let us know.

    Regarding this particular issue, I don't see how it's actionable at this moment so I will go ahead and close it for now.

  6. whyboris commented on Sep 28, 2019

    @whyboris
    Author

    Thank you @JoostK -- hope the time you spent looking into this issue wasn't a waste. I think it's very sensible for Angular to allow for some outdated versions of libraries to not be compatible with new versions of Angular 👌

    For anyone coming across similar problems upgrading to Angular 9, the best recommendation is:

    • Update the library mydatepicker to its successor angular-mydatepicker

    This is a sensible solution because mydatepicker hasn't been updated in 1 year: https://www.npmjs.com/package/mydatepicker?activeTab=versions

    And its official repository (https://github.com/kekeh/mydatepicker) recommends you upgrade to the successor (https://github.com/kekeh/angular-mydatepicker), also written by the same author. This new version was released as recently as 2 months ago: https://www.npmjs.com/package/angular-mydatepicker

    👏 keep 👏 dependencies 👏 up 👏 to 👏 date 👏

    Cheers ❤️

  7. angular-automatic-lock-bot commented on Oct 29, 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.

  8. locked and limited conversation to collaborators on Oct 29, 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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions