我正在尝试使用角度为1.6和5的混合应用程序 . 手动引导有效 . 一旦我尝试引导混合应用程序,我就会收到以下错误:
compiler.js?7e34:466未捕获错误:无法解析AppModule的所有参数:(?) . at syntaxError(eval at(app.bundle.js:1852),:684:34)at CompileMetadataResolver._getDependenciesMetadata(eval at(app.bundle.js:1852),:15765:35)at CompileMetadataResolver._getTypeMetadata(eval at( app.bundle.js:1852),:15600:26)at 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)at JitCompiler.compileModuleAsync(eval at(app.bundle.js:1852),:33637: 37)at CompilerImpl.compileModuleAsync(eval at(app.bundle.js:1864),:245:49)at PlatformRef.bootstrapModule(eval at(app.bundle.js:229),:5646:25)at eval(eval) at(app.bundle.js:827),:76:53)
app.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'
},
2 回答
至于代码你've shared everything seems to be in order. It could be though, that you'再使用另一个注释库's clashing with Angular'的装饰器 . 例如,如果您使用angular-ts-decorators,肯定会导致这样的问题 .
如果是这种情况 - 删除其他注释库(现在应该是冗余的)并使用Angular的注释 .
在我的情况下加载JS后,它开始工作: