angular: AoT Compiler unable to resolve module with "export default class"
I’m submitting a …
[x] bug report => search github for a similar issue or PR before submitting
Current behavior To allow a module to be loaded lazily, I define its route like so:
{
path: 'report',
loadChildren: '/app/report/report.module'
}
And I declare it as the default class in report.module.ts so the router will know what to load:
export default class ReportModule {}
Using export default class ReportModule {}
instead of export class ReportModule {}
when declaring modules breaks ngc
. During compilation I get error:
can't resolve module C:/path/to/report.module.ts from C:/path/to/report.module.ts
Error: can't find symbol ReportModule exported from module C:/path/to/report.module.ts
at ReflectorHost.findDeclaration (C:\path\to\@angular\compiler-cli\src\reflector_host.js:174:23)
at _loop_1 (C:\path\to\@angular\compiler-cli\src\codegen.js:52:51)
...
Compilation failed
I left the orientation of the slashes (forward /
and back \
) as they appear in the console
Expected/desired behavior
An earlier version of the docs on ngModule
suggested using export default
to expose lazy-loaded modules. This works well with Just-in-Time compilation. So I expected the AoT compiler to be able to parse them as well
Reproduction of the problem
Try compiling an application with a module declared with export default
Please tell us about your environment:
- Angular version: 2.0.0-rc.6
- Browser: [all]
- Language: [TypeScript 2]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 45
- Comments: 34 (14 by maintainers)
Commits related to this issue
- implemented (but not tested) AOT. At the moment I cannot compile with aot, because there is a bug in angular2 https://github.com/angular/angular/issues/11402 — committed to Ks89/My-MEAN-website-server by Ks89 8 years ago
- implemented (but not tested) AOT. At the moment I cannot compile with aot, because there is a bug in angular2 https://github.com/angular/angular/issues/11402 — committed to Ks89/My-MEAN-website-server by Ks89 8 years ago
- Remove default exports. Default exports are unsupported in the AOT-TSC. Issue: https://github.com/angular/angular/issues/11402 — committed to jp-hoehmann/aldo by jp-hoehmann 7 years ago
- feat(@ngtools/webpack): support import syntax for loadChildren with ViewEngine This feature ONLY matches the format below: ``` loadChildren: () => import('IMPORT_STRING').then(m => m.EXPORT_NAME) ```... — committed to filipesilva/angular-cli by filipesilva 5 years ago
- feat(@ngtools/webpack): support import syntax for loadChildren with ViewEngine This feature ONLY matches the format below: ``` loadChildren: () => import('IMPORT_STRING').then(m => m.EXPORT_NAME) ```... — committed to filipesilva/angular-cli by filipesilva 5 years ago
- feat(@ngtools/webpack): support import syntax for loadChildren with ViewEngine This feature ONLY matches the format below: ``` loadChildren: () => import('IMPORT_STRING').then(m => m.EXPORT_NAME) ```... — committed to filipesilva/angular-cli by filipesilva 5 years ago
- feat(@ngtools/webpack): support import syntax for loadChildren with ViewEngine This feature ONLY matches the format below: ``` loadChildren: () => import('IMPORT_STRING').then(m => m.EXPORT_NAME) ```... — committed to filipesilva/angular-cli by filipesilva 5 years ago
- feat(@ngtools/webpack): support import syntax for loadChildren with ViewEngine This feature ONLY matches the format below: ``` loadChildren: () => import('IMPORT_STRING').then(m => m.EXPORT_NAME) ```... — committed to filipesilva/angular-cli by filipesilva 5 years ago
- feat(@ngtools/webpack): support import syntax for loadChildren with ViewEngine This feature ONLY matches the format below: ``` loadChildren: () => import('IMPORT_STRING').then(m => m.EXPORT_NAME) ```... — committed to angular/angular-cli by filipesilva 5 years ago
@frankforward don’t use default exports 😃
Same question here, any updates on when default exports will be supported by the AoT compiler?
Wow, 2019 is coming to an end, the problem still exist
I spent two hours tracing this down in my app. Googling the error message didn’t lead anywhere. Once I discovered it (by accident), I finally found this issue. In my case, the error message was slightly different and even less helpful:
Unexpected value 'null' declared by the module AppModule
.Please make this a priority so other devs won’t waste time like I did.
Just place both export types and it works:
@NgModule({})
export class MyModule { }
export default MyModule;
Sorry, this is not priority, but we would accept a PR.
On Thu, Jan 26, 2017 at 6:28 AM, Peter Grman notifications@github.com wrote:
Any updates? I have the same problem with Angular 2.1.0 and typescript 2.0.3. Can we use “export default class” or not? It is useful to know if we must remove all default exports or not.
Thank u.
What if I’m building an Angular component library, and have an embedded third party lib that uses default exports, I have no control over it, and my lib doesn’t build because of this.
Hey folks,
default exports are now working in the Ivy compiler!
This can be fixed by providing the exported class through a factory provider. The following is an example providing
MarkerClusterer
from@google/markerclustererplus
:This is still a thing, error message could be better: ‘ERROR in : Unexpected value ‘null’ imported by the module’ when you export a routing module as default.
If I hadn’t found a thread referencing the same error this would’ve been a pain to solve.
Why not just making a PR if you really need that rather than waiting for years, this is open-source project…
@pavel-agarkov When I place both exports, AOT compiles, but I get the following error in production:
ERROR Error: Uncaught (in promise): Error: Cannot find 'default' in './registration/registration.module' Error: Cannot find 'default' in './registration/registration.module'
Hi, 4 months ago @robwormald wrote in https://github.com/angular/angular/issues/11975#issuecomment-250427362
Since than I didn’t find anything tangible if it will take another month, year or decade. Is there any chance that this would get supported with the upcoming version 4?
I think the compiler / codgen pipeline in general doesn’t handle default exports (yet)