question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Compiler compileModuleAndAllComponentsAsync declaration of null

See original GitHub issue

🐞 bug report

Affected Package

@angular/core the function compileModuleAndAllComponentsAsync in angular/core compiler is not loading module anymore:

Is this a regression?

Yes, we were totally using this with angular 8 compiler Hello there, I’m sorry to bother you here guys. But we are trying to upgrade our angular application to your new patch angular 9 ivy with AOT compilation. We have a main feature that is to load stand alone angular module precompiled to .umd.js file. And we load them in our main angular application at runtime. For this we were using this at the moment . Our url is our own application and the file is located in our assets folder which is publicly served from our app

`      return SystemJS.import(url)
        .then((module: any) => {
          return module[moduleInfo.moduleName]
        })
        .then(
          module => {
            console.log(module)
            return this.compiler
              .compileModuleAndAllComponentsAsync(module)
              .then(_compiled => {
                return module
              })
              .catch(error => {
                console.error('ERROR in SystemJS compile with module', {
                  error,
                  module
                })

                // tslint:disable-next-line: rxjs-throw-error
                throw { error, module }
              })
          }
          // console.error.bind(console))
        )`

Description

I put in this file an example umd.js file that we were loading at runtime

🔥 Exception or Error


core.js:3872 ERROR TypeError: Cannot read property 'declarations' of null
    at Compiler_compileModuleAndAllComponentsSync__POST_R3__ (core.js:27418)
    at Compiler_compileModuleAndAllComponentsAsync__POST_R3__ [as compileModuleAndAllComponentsAsync] (core.js:27429)
    at module.service.ts:182
    at ZoneDelegate.invoke (zone.js:396)
    at Object.onInvoke (core.js:27800)
    at ZoneDelegate.invoke (zone.js:395)
    at Zone.run (zone.js:153)
    at zone.js:894
    at ZoneDelegate.invokeTask (zone.js:431)
    at Object.onInvokeTask (core.js:27788)

🌍 Your Environment

Angular Version:


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.6
Node: 12.16.1
OS: win32 x64

Angular: 9.0.6
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker
Ivy Workspace: Yes

Package                                    Version
--------------------------------------------------------------------
@angular-devkit/architect                  0.900.6
@angular-devkit/build-angular              0.900.6
@angular-devkit/build-ng-packagr           0.900.6
@angular-devkit/build-optimizer            0.900.6
@angular-devkit/build-webpack              0.900.6
@angular-devkit/core                       8.1.3
@angular-devkit/schematics                 8.1.3
@angular/cdk                               9.1.1
@angular/http                              8.0.0-beta.10
@angular/material                          9.1.1
@angular/material-moment-adapter           9.1.1
@angular/pwa                               0.801.3
@ngtools/webpack                           9.0.6
@nguniversal/common                        9.0.1
@nguniversal/express-engine                9.0.1
@nguniversal/module-map-ngfactory-loader   8.2.6
@schematics/angular                        8.1.3
@schematics/update                         0.900.6
ng-packagr                                 9.0.0
rxjs                                       6.5.4
typescript                                 3.6.5
webpack                                    4.41.2

Anything else relevant?

modula.umd.js renamed for pasting to modulea.umd.js.txt

modulea.umd.js.txt

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
Razgortcommented, Mar 18, 2020

Thanks for pointed this out !! We thought that was what we missed, but when we removed it. The plugin seems to be loaded so it’s ok. But when trying to route to the library module

image See attached picture error :

ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘ɵmod’ of undefined TypeError: Cannot read property ‘ɵmod’ of undefined at getNgModuleDef (core.js:1869) at new NgModuleFactory (core.js:24579) at Compiler_compileModuleSync__POST_R3__ (core.js:27406) at Compiler_compileModuleAsync__POST_R3__ [as compileModuleAsync] (core.js:27411)

Thanks anyway your help is much appreciated and I’m grats for that

4reactions
victory-okicommented, May 20, 2020

@Borsi92 I had the same issue but I eventually found out that my lazy loading script was wrong this was what I had path:'modulePath', loadChildren:()=>import('../some-module/some-module.module').then(m=>{m.some-module}) this is what it should have been path:'modulePath', loadChildren:()=>import('../some-module/some-module.module').then(m=>m.some-module) turns out i didn’t return the module in the arrow function. I don’t know if this helps, but this is the issue I had and how I solved it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compiler - Angular
Low-level service for running the angular compiler during runtime to create ComponentFactory ... compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>): ...
Read more >
Not able to inject a service in dynamic component using JIT ...
I've found that simply passing the service like a variable worked just fine this.compiler.compileModuleAndAllComponentsAsync(tmpModule) ...
Read more >
Playing With The Angular Compiler As A Service
*This post belongs to a series I have been writing to help people learn The Angular framework. You can check out other tutorials...
Read more >
Here is what you need to know about dynamic components in ...
Here is what you need to know about dynamic components in Angular · Component factory and compiler · Angular modules and ComponentFactoryResolver ·...
Read more >
Problem with dynamic component modules after upgrade from ...
compileModuleAndAllComponentsAsync (tmpModule) .then((factories) ... It seems that with angular 9 JIT compiler does not work with AOT enabled ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found