Title: import() feature doesn't work in production script to load modules or plugins dynamically · Issue #7703 · angular/angular-cli · GitHub
Open Graph Title: import() feature doesn't work in production script to load modules or plugins dynamically · Issue #7703 · angular/angular-cli
X Title: import() feature doesn't work in production script to load modules or plugins dynamically · Issue #7703 · angular/angular-cli
Description: Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [ ] feature request Versions. $ ng -v _ _ ____ _ ___ / \ _ __ __ _ _ | | __ _ _ __ / | | | | / △ \ | ' \ / _ | | | | |/ _ | '| | ...
Open Graph Description: Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [ ] feature request Versions. $ ng -v _ _ ____ _ ___ / \ _ __ __ _ _ | | __ _ _ __ / | | ...
X Description: Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [ ] feature request Versions. $ ng -v _ _ ____ _ ___ / \ _ __ __ _ _ | | __ _ _ __ / |...
Opengraph URL: https://github.com/angular/angular-cli/issues/7703
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"import() feature doesn't work in production script to load modules or plugins dynamically","articleBody":"\u003c!--\r\nIF YOU DON'T FILL OUT THE FOLLOWING INFORMATION YOUR ISSUE MIGHT BE CLOSED WITHOUT INVESTIGATING\r\n-->\r\n### Bug Report or Feature Request (mark with an `x`)\r\n```\r\n- [ ] bug report -> please search issues before submitting\r\n- [ ] feature request\r\n```\r\n\r\n### Versions.\r\n\u003c!--\r\nOutput from: `ng --version`.\r\nIf nothing, output from: `node --version` and `npm --version`.\r\n Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)\r\n-->\r\n$ ng -v\r\n _ _ ____ _ ___\r\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\r\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\r\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\r\n/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\r\n |___/\r\n@angular/cli: 1.4.1\r\nnode: 6.10.0\r\nos: win32 x64\r\n@angular/animations: 4.3.6\r\n@angular/common: 4.3.6\r\n@angular/compiler: 4.3.6\r\n@angular/core: 4.3.6\r\n@angular/forms: 4.3.6\r\n@angular/http: 4.3.6\r\n@angular/platform-browser: 4.3.6\r\n@angular/platform-browser-dynamic: 4.3.6\r\n@angular/router: 4.3.6\r\n@angular/upgrade: 4.3.6\r\n@angular/cli: 1.4.1\r\n@angular/compiler-cli: 4.3.6\r\n@angular/language-service: 4.3.6\r\ntypescript: 2.4.2\r\n\r\nnode --version\r\nv6.10.0\r\n\r\n### Repro steps.\r\n\u003c!--\r\nSimple steps to reproduce this bug.\r\nPlease include: commands run, packages added, related code changes.\r\nA link to a sample repo would help too.\r\n-->\r\nI am developing a plugin based app where plugins are loading dynamically. At the beginning, the plugins are unknown by the app i.e. the plugins are stored in a folder in the app. Now, I tried to load the plugin modules dynamically using `import()` method and compile to load the module and entryComponents using the following code. \r\n```\r\nexport class DynamicComponent { \r\n injector: Injector;\r\n compiler: Compiler;\r\n @ViewChild('container', {read: ViewContainerRef}) \r\n container: ViewContainerRef; \r\n componentRef: any; \r\n\r\n constructor(private compFactoryResolver: ComponentFactoryResolver, injector: Injector,\r\n private apiService: apiService) {\r\n\r\n this.injector = ReflectiveInjector.resolveAndCreate(COMPILER_PROVIDERS, injector);\r\n this.compiler = this.injector.get(Compiler);\r\n }\r\n addWidget(){\r\n\r\n apiService.getMoudleUrls().subscribe( module_url=>{\r\n let module_= import(module_url); //e.g './data-widget/data-widget.module' \r\n module_.then(module_data =>{\r\n\r\n const keys = Object.getOwnPropertyNames( module_data );\r\n let moduleFactories = this.compiler.compileModuleAndAllComponentsSync(module_data[keys[1]]);\r\n const moduleRef = moduleFactories.ngModuleFactory.create(this.injector);\r\n const componentFactory = moduleFactories.componentFactories\r\n .find(e => e.selector === 'data-widget'); // find the entry component using selector \r\n this.componentRef = this.container.createComponent(componentFactory, null, moduleRef.injector);\r\n\r\n const newItem: WidgetComponent = this.componentRef.instance; \r\n },\r\n error=>{});\r\n }\r\n }\r\n```\r\nExample module and components of the plugins are\r\n\r\n```\r\ndata-widget.module.ts\r\n\r\n@NgModule({\r\n imports: [ ...,\r\n declarations: [DataWidget],\r\n exports: [DataWidget], \r\n providers: [],\r\n entryComponents: [DataWidget] \r\n})\r\nexport class DataWidgetModule {\r\n constructor(private widgetService: widgetService) {\r\n widgetService.register('weather', DataWidget); \r\n } \r\n }\r\ndata-widget.component:\r\n\r\n@Component({\r\n selector: 'data-widget',\r\n templateUrl: 'data-widget.component.html'\r\n })\r\n export class DataWidget{}\r\n```\r\nits working perfectly in developing mode with typescript. **The problem start in production generated script**. I build the project using `ng build --prod ` and get `Javascript` bundles. \r\nI tried two process to transpile typescript to javascript\r\n1. plugins library in javascript format using https://github.com/jvandemo/generator-angular2-library. and\r\n2. build plugins using `tsc` command\r\n\r\nThen I tried to add the plugins by providing the URLs of the index.js (generated by no 1. process) and also tried to give URL of data-widget.module.js (generated by no 2. process). But I am failed to load the plugins and getting an error like `ERROR Error: Uncaught (in promise): Error: No NgModule metadata found for 'undefined'.`\r\n\r\n### The log given by the failure.\r\n\u003c!-- Normally this include a stack trace and some more information. -->\r\nERROR Error: Uncaught (in promise): Error: No NgModule metadata found for 'undefined'.\r\nError: No NgModule metadata found for 'undefined'.\r\n at t.resolve (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.getNgModuleMetadata (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t._loadModules (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t._compileModuleAndAllComponents (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.compileModuleAndAllComponentsSync (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at main.f86f90a36f2a8d2bd8a0.bundle.js:1\r\n at t.invoke (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at Object.onInvoke (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.invoke (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at r.run (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at t.resolve (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.getNgModuleMetadata (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t._loadModules (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t._compileModuleAndAllComponents (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.compileModuleAndAllComponentsSync (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at main.f86f90a36f2a8d2bd8a0.bundle.js:1\r\n at t.invoke (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at Object.onInvoke (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.invoke (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at r.run (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at c (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at c (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at polyfills.d1f049ba48d63f223a98.bundle.js:1\r\n at t.invokeTask (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at Object.onInvokeTask (vendor.6269afbd95f1ed5b8299.bundle.js:1)\r\n at t.invokeTask (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at r.runTask (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at o (polyfills.d1f049ba48d63f223a98.bundle.js:1)\r\n at \u003canonymous>\r\n\r\n### Desired functionality.\r\n\u003c!--\r\nWhat would like to see implemented?\r\nWhat is the usecase?\r\n-->\r\nWould like to load modules or plugins dynamically in production generated script as it loaded in developing mode.\r\n\r\n### Mention any other details that might be useful.\r\nTo make import() feature work, the following changes are necessary.\r\n1. typescript version 2.4\r\n2. in tsconfig.json file, change `module: esnext` \r\n","author":{"url":"https://github.com/khaled-ansary","@type":"Person","name":"khaled-ansary"},"datePublished":"2017-09-15T10:33:22Z","url":"https://github.com/angular/angular-cli/issues/7703"}
| 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:fbc69667-ce8f-e7af-474a-a46f2371b865 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8DE:33F146:D842CD:116FB8C:6B00F4CA |
| html-safe-nonce | 770cf5d9cfefcf45f4f017fafdb7d9230f0c1f5034b3ddaf7c606e9accc0447c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOERFOjMzRjE0NjpEODQyQ0Q6MTE2RkI4Qzo2QjAwRjRDQSIsInZpc2l0b3JfaWQiOiI3Mzk1ODU5NTU0MzcxNjk1ODE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c3de0a6b4ee1e48e6e4ce3db9de303378c553543151abe484448811857845013 |
| hovercard-subject-tag | issue:257996830 |
| 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-cli/7703/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b23e239cf81a944fa1d840c430fc44a7cd79bf49f7416237276dfb14323335ad/angular/angular-cli/issues/7703 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b23e239cf81a944fa1d840c430fc44a7cd79bf49f7416237276dfb14323335ad/angular/angular-cli/issues/7703 |
| og:image:alt | Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [ ] feature request Versions. $ ng -v _ _ ____ _ ___ / \ _ __ __ _ _ | | __ _ _ __ / | | ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | khaled-ansary |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width