René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:fbc69667-ce8f-e7af-474a-a46f2371b865
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE8DE:33F146:D842CD:116FB8C:6B00F4CA
html-safe-nonce770cf5d9cfefcf45f4f017fafdb7d9230f0c1f5034b3ddaf7c606e9accc0447c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOERFOjMzRjE0NjpEODQyQ0Q6MTE2RkI4Qzo2QjAwRjRDQSIsInZpc2l0b3JfaWQiOiI3Mzk1ODU5NTU0MzcxNjk1ODE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacc3de0a6b4ee1e48e6e4ce3db9de303378c553543151abe484448811857845013
hovercard-subject-tagissue:257996830
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/7703/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b23e239cf81a944fa1d840c430fc44a7cd79bf49f7416237276dfb14323335ad/angular/angular-cli/issues/7703
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b23e239cf81a944fa1d840c430fc44a7cd79bf49f7416237276dfb14323335ad/angular/angular-cli/issues/7703
og:image:altBug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [ ] feature request Versions. $ ng -v _ _ ____ _ ___ / \ _ __ __ _ _ | | __ _ _ __ / | | ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekhaled-ansary
hostnamegithub.com
expected-hostnamegithub.com
None4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc
turbo-cache-controlno-preview
go-importgithub.com/angular/angular-cli git https://github.com/angular/angular-cli.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id36891867
octolytics-dimension-repository_nwoangular/angular-cli
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id36891867
octolytics-dimension-repository_network_root_nwoangular/angular-cli
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9983dd5da06943f833c971dd5b6bc988e2858be5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular-cli/issues/7703#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F7703
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F7703
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular-cli
Reloadhttps://github.com/angular/angular-cli/issues/7703
Reloadhttps://github.com/angular/angular-cli/issues/7703
Reloadhttps://github.com/angular/angular-cli/issues/7703
angularhttps://github.com/angular
angular-clihttps://github.com/angular/angular-cli
Codehttps://github.com/angular/angular-cli
Issues198 (198)https://github.com/angular/angular-cli/issues
Pull requests23 (23)https://github.com/angular/angular-cli/pulls
Actionshttps://github.com/angular/angular-cli/actions
Security and quality8 (8)https://github.com/angular/angular-cli/security
Insightshttps://github.com/angular/angular-cli/insights
https://github.com/angular/angular-cli
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/7703
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/7703
import() feature doesn't work in production script to load modules or plugins dynamicallyhttps://github.com/angular/angular-cli/issues/7703#top
https://github.com/khaled-ansary
khaled-ansaryhttps://github.com/khaled-ansary
on Sep 15, 2017https://github.com/angular/angular-cli/issues/7703#issue-257996830
https://github.com/jvandemo/generator-angular2-libraryhttps://github.com/jvandemo/generator-angular2-library
khaled-ansaryhttps://github.com/khaled-ansary
on Sep 15, 2017https://github.com/angular/angular-cli/issues/7703#event-1251024516
https://github.com/filipesilva
filipesilvahttps://github.com/filipesilva
on Sep 22, 2017https://github.com/angular/angular-cli/issues/7703#issuecomment-331484538
#4541https://github.com/angular/angular-cli/issues/4541
filipesilvahttps://github.com/filipesilva
completedhttps://github.com/angular/angular-cli/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 22, 2017https://github.com/angular/angular-cli/issues/7703#event-1261496139
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Sep 7, 2019https://github.com/angular/angular-cli/issues/7703#issuecomment-529104807
automatic conversation locking policyhttps://github.com/angular/angular/blob/67d80f/docs/GITHUB_PROCESS.md#conversation-locking
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Sep 7, 2019https://github.com/angular/angular-cli/issues/7703#event-2616188093
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular-cli/issues/7703
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/7703
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.