我正在尝试运行角度为 1.6 和 5 的混合应用程序。手动引导有效。一旦我尝试引导混合应用程序,就会收到以下错误:
compiler.js?7e34:466 Uncaught Error: Can't resolve all parameters for AppModule: (?). 在 CompileMetadataResolver._getDependenciesMetadata 处的 syntaxError (eval at (app.bundle.js:1852), :684:34) 在 CompileMetadataResolver._getTypeMetadata (eval at ( app.bundle.js:1852), :15600:26) 在 CompileMetadataResolver.getNgModuleMetadata (eval at (app.bundle.js:1852), :15399:24) at JitCompiler._loadModules (eval at (app.bundle.js: 1852), :33760:87) 在 JitCompiler._compileModuleAndComponents (eval at (app.bundle.js:1852), :33721:36) 在 JitCompiler.compileModuleAsync (eval at (app.bundle.js:1852), :33637: 37) 在 CompilerImpl.compileModuleAsync (eval at (app.bundle.js:1864), :245:49) 在 PlatformRef.bootstrapModule (eval at (app.bundle.js:229), :5646:
应用程序.ts
platformBrowserDynamic().bootstrapModule(AppModule);
app.module.ts
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {UpgradeModule} from '@angular/upgrade/static';
@NgModule({
imports: [
BrowserModule,
UpgradeModule
]
})
export class AppModule {
constructor(private upgrade: UpgradeModule) {
}
ngDoBootstrap() {
this.upgrade.bootstrap(document.documentElement, ['myApp']);
}
}
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
我正在使用 webpack。这是我的配置的一部分:
resolve: {
extensions: ['.js', '.ts'],
alias: {
"@angular/upgrade/static": "@angular/upgrade/bundles/upgrade-static.umd.js"
}
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: '/node_modules'
},