您需要包含core-js
shim 库,以便 Angular 代码可以使用Reflect.getOwnMetadata
方法从装饰类中读取元数据
索引.ejs
<% if (isLocal) { %>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <== add this
<script type="systemjs-importmap">
....
您将使用哪个 core-js 版本并不重要,但它应该包含用于reflect.get-own-metadata
.
例如,您还可以使用<script src='https://unpkg.com/core-js-bundle@3.1.4/minified.js'></script>
默认情况下,Angular CLI 在 jit 中添加了这个polyfills.ts
polyfill。但是single-spa-angular
删除了这个 polyfill。
请注意,您还应该将 zone.js 包含到您的文件中,以便完整的代码看起来像
索引.ejs
<script src='https://unpkg.com/core-js-bundle@3.1.4/minified.js'></script>
<script src="https://unpkg.com/zone.js"></script>
更新
该错误Class constructor I cannot be invoked without 'new'
来自 rxjs bundle( @esm-bundle/rxjs@6.5.4/system/rxjs.min.js
),这意味着该 bundle 没有正确构建以在浏览器中使用它(更多关于此错误的信息,请参见Javascript ES6 TypeError: Class constructor Client cannot be invoked without 'new')。
您可以将 umd 捆绑包用于 rxjs
"rxjs": "https://cdn.jsdelivr.net/npm/rxjs@6.5.4/bundles/rxjs.umd.min.js",
"rxjs/operators": "https://cdn.jsdelivr.net/npm/@esm-bundle/rxjs@6.5.4/system/rxjs-operators.min.js",
我将在下面分享整个inject.ejs
文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Root Config</title>
<meta name="importmap-type" content="systemjs-importmap" />
<% if (isLocal) { %>
<!--<script src="https://unpkg.com/core-js@2.6/client/shim.min.js"></script>-->
<script type="systemjs-importmap">
{
"imports": {
"@example/root-config": "http://localhost:9000/root-config.js",
"@example/angular": "http://localhost:4200/main.js",
"single-spa": "https://cdnjs.cloudflare.com/ajax/libs/single-spa/5.1.0/system/single-spa.dev.js",
"rxjs": "https://cdn.jsdelivr.net/npm/rxjs@6.5.4/bundles/rxjs.umd.min.js",
"rxjs/operators": "https://cdn.jsdelivr.net/npm/@esm-bundle/rxjs@6.5.4/system/rxjs-operators.min.js",
"@angular/core": "https://unpkg.com/@angular/core@8.2.14/bundles/core.umd.js",
"@angular/compiler": "https://unpkg.com/@angular/compiler@8.2.14/bundles/compiler.umd.js",
"@angular/common": "https://unpkg.com/@angular/common@8.2.14/bundles/common.umd.min.js",
"@angular/common/http": "https://unpkg.com/@angular/common@8.2.14/bundles/common-http.umd.min.js",
"@angular/platform-browser-dynamic": "https://unpkg.com/@angular/platform-browser-dynamic@8.2.14/bundles/platform-browser-dynamic.umd.min.js",
"@angular/platform-browser": "https://unpkg.com/@angular/platform-browser@8.2.14/bundles/platform-browser.umd.min.js",
"@angular/platform-browser/animations": "https://unpkg.com/@angular/platform-browser@8.2.14/bundles/platform-browser-animations.umd.min.js",
"@angular/forms": "https://unpkg.com/@angular/forms@8.2.14/bundles/forms.umd.min.js",
"@angular/router": "https://unpkg.com/@angular/router@8.2.14/bundles/router.umd.min.js",
"@angular/animations": "https://unpkg.com/@angular/animations@8.2.14/bundles/animations.umd.js",
"@angular/animations/browser": "https://unpkg.com/@angular/animations@8.2.14/bundles/animations-browser.umd.min.js",
"tslib": "https://cdnjs.cloudflare.com/ajax/libs/tslib/1.10.0/tslib.min.js",
"zone.js": "https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.9.1/zone.min.js"
}
}
</script>
<% } %>
<script src='https://unpkg.com/core-js-bundle@3.1.4/minified.js'></script>
<script src="https://unpkg.com/zone.js"></script>
<script src="https://cdn.jsdelivr.net/npm/import-map-overrides/dist/import-map-overrides.js"></script>
<script src="https://cdn.jsdelivr.net/npm/systemjs/dist/system.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/systemjs/dist/extras/amd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/systemjs/dist/extras/named-exports.min.js"></script>
</head>
<body>
<main id="main"></main>
<script>
System.import("@example/root-config");
</script>
<import-map-overrides-full show-when-local-storage="devtools" dev-libs></import-map-overrides-full>
</body>
</html>