I'm currently trying to lower build times by externalizing Angular dependencies through Webpack externals. So far, I have achieved this wihout problems for React and other minor libraries.
If I just move '@angular/compiler' it also works, however when externalizing '@angular/core' and the others I receive a Can't resolve all parameters for ApplicationModule: (?) at at syntaxError (util.ts:100) at CompileMetadataResolver._getDependenciesMetadata (metadata_resolver.ts:957) ...
error when bootstrapping the app.
The files that I'm using are the 8.2.14 UMD bundles you can find in unpkg.com and my externals are:
[
/^@example\,
/^rxjs$/,
/^rxjs\/operators$/,
/^@angular\/core$/,
/^@angular\/compiler$/,
/^@angular\/common$/,
/^@angular\/common\/http$/,
/^@angular\/forms$/,
/^@angular\/platform-browser$/,
/^@angular\/platform-browser-dynamic$/,
/^@angular\/router$/,
/^zone\.js$/,
/^single-spa$/
]
The rxjs bundles are the ones found here https://cdn.jsdelivr.net/npm/@esm-bundle.
You can see the error on this repo: https://github.com/OriolInvernonLlaneza/test-share-angular
Thanks in advance!
Edit: Thanks to yurzui's answer this error was solved. However, I now receive another error:
Class constructor I cannot be invoked without 'new'
at new EventEmitter (event_emitter.ts:78)
at new NgZone (ng_zone.ts:97)
at getNgZone (application_ref.ts:358)
at PlatformRef.bootstrapModuleFactory (application_ref.ts:255)
at application_ref.ts:308
You need to include
core-js
shim library so that Angular code can useReflect.getOwnMetadata
method to read metadata from decorated classesindex.ejs
It doesn't matter which core-js version you will use but it should contain polyfill for
reflect.get-own-metadata
.For example you can also use
<script src='https://unpkg.com/[email protected]/minified.js'></script>
Angular CLI adds this polyfill by default in
polyfills.ts
for jit. Butsingle-spa-angular
removes this polyfill.Note that you should also include zone.js to your file so the complete code should look like
index.ejs
Update
The error
Class constructor I cannot be invoked without 'new'
comes from rxjs bundle(@esm-bundle/[email protected]/system/rxjs.min.js
) which means that this bundle wasn't built properly for using it in browser(more on this error here Javascript ES6 TypeError: Class constructor Client cannot be invoked without 'new').You can use umd bundle for rxjs
I will share the whole
inject.ejs
file below