I have an micro app element and a shell app which works fine normally. However, I'm trying to build the micro app without the common libraries and refer to them from the global scope. I followed the following tutorial Building angular elements with sharing libraries
- ng g ngx-build-plus:externals
- npm run build:externals (ng serve --extra-webpack-config webpack.externals.js --output-hashing none --single-bundle)
The file webpack.externals.js has the following externals defined
module.exports = { "externals": { "rxjs": "rxjs", "@angular/core": "ng.core", "@angular/common": "ng.common", "@angular/common/http": "ng.common.http", "@angular/platform-browser": "ng.platformBrowser", "@angular/platform-browser-dynamic": "ng.platformBrowserDynamic", "@angular/compiler": "ng.compiler", "@angular/elements": "ng.elements", // Uncomment and add to scripts in angular.json if needed // "@angular/router": "ng.router", // "@angular/forms": "ng.forms" } }
In the angular.json te following scripts are there
"scripts": [
"node_modules/rxjs/bundles/rxjs.umd.js",
"node_modules/@angular/core/bundles/core.umd.js",
"node_modules/@angular/common/bundles/common.umd.js",
"node_modules/@angular/common/bundles/common-http.umd.js",
"node_modules/@angular/compiler/bundles/compiler.umd.js",
"node_modules/@angular/elements/bundles/elements.umd.js",
"node_modules/@angular/platform-browser/bundles/platform-browser.umd.js",
"node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"
]
But now, the element is not loading in the shell app. It says "Uncaught ReferenceError: ng is not defined at Object.@angular/core". I'm very new to angular, ave I missed a step here? It looks like the angular.json scripts are not working and element (micro app) is unable to refer to the global array
I had same issue as yours, I am trying to embed an angular element into an angular app with ng-build-plus, this is how I resolved it: