You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AoT Compiler unable to resolve module with "export default class" #11402
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]
Reacted by Johan Björklund, Alexander Trakhimenok, Aluan Haddad, Marko Kaznovac, Dustin Charles, Ryan Pierce, Peter Persson, Stefano Cappa, Johannes Rudolph, Adrian Teh and 34 more
changed the title [-]AoT Compiler unable to parse valid typescript: "export default class"[/-][+]AoT Compiler unable to resolve module with "export default class"[/+]on Sep 8, 2016
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.
This can be fixed by providing the exported class through a factory provider. The following is an example providing MarkerClusterer from @google/markerclustererplus:
importMarkerClustererfrom'@google/markerclustererplus';exportconstMARKER_CLUSTERER_CLASS=newInjectionToken<new(...args: any)=>MarkerClusterer>('MarkerClustererPlus class from @google/markerclustererplus',);exportfunctionmarkerClustererClassFactory(): new(...args: any)=>MarkerClusterer{returnMarkerClusterer;}
@NgModule({providers: [{provide: MARKER_CLUSTERER_CLASS,useFactory: markerClustererClassFactory},],})exportclassSomeModule{}
@Injectable()exportclassSomeService{constructor(@Inject(MARKER_CLUSTERER_CLASS)privatemarkerClustererClass){}}
Activity
vicb commentedon Sep 7, 2016
/cc @chuckjaz
vicb commentedon Sep 8, 2016
@mhevery @alexeagle Chuck says this is related to your module resolution changes.
[-]AoT Compiler unable to parse valid typescript: "export default class"[/-][+]AoT Compiler unable to resolve module with "export default class"[/+]mhevery commentedon Sep 10, 2016
@vsavkin it seems like the Router does not understand default exports?
alexeagle commentedon Sep 11, 2016
No, this is in ReflectorHost so I don't think it's router-specific.
robwormald commentedon Sep 11, 2016
I think the compiler / codgen pipeline in general doesn't handle default exports (yet)
34 remaining items
feat(@ngtools/webpack): support import syntax for loadChildren with V…
feat(@ngtools/webpack): support import syntax for loadChildren with V…
spinspume commentedon May 29, 2019
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.
SchnWalter commentedon Sep 27, 2019
Haven't checked, but I just saw commint two commits that landed into Angular v9 and I think they might also solve this issue, see: 373e133 and c4e039a
Ni55aN commentedon Nov 12, 2019
Wow, 2019 is coming to an end, the problem still exist
montella1507 commentedon Nov 26, 2019
same for i18n and working solution
niklaas commentedon Jan 24, 2020
This can be fixed by providing the exported class through a factory provider. The following is an example providing
MarkerClustererfrom@google/markerclustererplus:JoostK commentedon Mar 15, 2020
Hey folks,
default exports are now working in the Ivy compiler!
angular-automatic-lock-bot commentedon Apr 15, 2020
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.