Title: Creating ROUTES with custom factory function ends up with "Cannot read property 'loadChildren' of undefined" error · Issue #22700 · angular/angular · GitHub
Open Graph Title: Creating ROUTES with custom factory function ends up with "Cannot read property 'loadChildren' of undefined" error · Issue #22700 · angular/angular
X Title: Creating ROUTES with custom factory function ends up with "Cannot read property 'loadChildren' of undefined" error · Issue #22700 · angular/angular
Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] Feature request [ ] Documentation issue o...
Open Graph Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] F...
X Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report <!-- Please search GitHub for a similar issue or PR before submitting --...
Opengraph URL: https://github.com/angular/angular/issues/22700
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Creating ROUTES with custom factory function ends up with \"Cannot read property 'loadChildren' of undefined\" error","articleBody":"## I'm submitting a...\r\n\r\n```\r\n[ ] Regression (a behavior that used to work and stopped working in a new release)\r\n[x] Bug report \u003c!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[ ] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n```\r\n\r\n## Current behavior\r\n\r\nWhen angular compiler finds a provider that defines `ROUTES`, but which doesn't have a `useValue` property, (because it has f.e. `useFactory` property instead) it fails with the following error:\r\n\r\n```\r\nERROR in TypeError: Cannot read property 'loadChildren' of undefined\r\n at _collectLoadChildren (/Users/jtomaszewski/src/recruitee/rails/admin_app/node_modules/@angular/compiler/bundles/compiler.umd.js:29034:20)\r\n at listLazyRoutes (/Users/jtomaszewski/src/recruitee/rails/admin_app/node_modules/@angular/compiler/bundles/compiler.umd.js:29009:49)\r\n at AotCompiler.listLazyRoutes (/Users/jtomaszewski/src/recruitee/rails/admin_app/node_modules/@angular/compiler/bundles/compiler.umd.js:31150:51)\r\n at AngularCompilerProgram.listLazyRoutes (/Users/jtomaszewski/src/recruitee/rails/admin_app/node_modules/@angular/compiler-cli/src/transformers/program.js:156:30)\r\n at AngularCompilerPlugin._listLazyRoutesFromProgram (/Users/jtomaszewski/src/recruitee/rails/admin_app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:304:38)\r\n at Promise.resolve.then.then (/Users/jtomaszewski/src/recruitee/rails/admin_app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:583:50)\r\n at process._tickCallback (internal/process/next_tick.js:109:7)\r\nwebpack: Failed to compile.\r\n```\r\n\r\n## Expected behavior\r\n\r\nDefining a provider for `ROUTES` with other providers like f.e. `FactoryProvider` should just work.\r\n\r\n## Minimal reproduction of the problem with instructions\r\n\r\n1. Write your module like this:\r\n\r\n```ts\r\nimport { NgModule, NgModuleFactory, Compiler } from '@angular/core';\r\nimport { Routes, RouterModule, ROUTES } from '@angular/router';\r\n\r\nexport function MainRoutingLazyRoutesFactory(compiler: Compiler): Routes {\r\n return [\r\n {\r\n path: 'dashboard',\r\n loadChildren: () => {\r\n return \u003cany>System.import('../features/dashboard/dashboard.module')\r\n .then(({ DashboardFeatureModule }) => DashboardFeatureModule)\r\n .then(ngModule => {\r\n if (ngModule instanceof NgModuleFactory) {\r\n return ngModule;\r\n } else {\r\n return compiler.compileModuleAsync(ngModule);\r\n }\r\n });\r\n },\r\n },\r\n ];\r\n}\r\n\r\n@NgModule({\r\n imports: [RouterModule],\r\n exports: [RouterModule],\r\n providers: [\r\n {\r\n provide: ROUTES,\r\n multi: true,\r\n deps: [Compiler],\r\n useFactory: MainRoutingLazyRoutesFactory,\r\n },\r\n ],\r\n})\r\nexport class MainRoutingModule {}\r\n```\r\n\r\n2. Try to compile it, in either JiT or AoT mode.\r\n\r\n## What is the motivation / use case for changing the behavior?\r\n\r\nIt lets you to easily implement lazy loaded modules in your routes with your custom way.\r\n\r\n## Environment\r\n\r\n```\r\nnode 6.11.5\r\nnpm 5.6.0\r\nangular 5.2.8\r\n@ngtools/webpack 1.10.2\r\n```","author":{"url":"https://github.com/jtomaszewski","@type":"Person","name":"jtomaszewski"},"datePublished":"2018-03-10T21:44:24Z","url":"https://github.com/angular/angular/issues/22700"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6cf2f32c-5ef3-91af-50dc-b21e0a101d21 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6A0:1F2D:2206AD:2B3502:6B00FCA3 |
| html-safe-nonce | 5d611d5c071e3981ab0a589a99cc163d38868c5a7819ec19c7a7848373cfa252 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkEwOjFGMkQ6MjIwNkFEOjJCMzUwMjo2QjAwRkNBMyIsInZpc2l0b3JfaWQiOiI3MjI0NTQzMDE5ODU1MzE0MDgzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2e6a18e68d903af8ee1201cf91af351b96a97bab51ce4dd834c50f384b303221 |
| hovercard-subject-tag | issue:304108106 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/22700/issue_layout |
| twitter:image | https://opengraph.githubassets.com/36f4237bc96cc4bf1778b17b7969c6359038eb6d97c24410d1aa8faf0d7e1c33/angular/angular/issues/22700 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/36f4237bc96cc4bf1778b17b7969c6359038eb6d97c24410d1aa8faf0d7e1c33/angular/angular/issues/22700 |
| og:image:alt | I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] F... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jtomaszewski |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width