版本9的Angular项目迁移问题与IVY编译器相关

4
我已经将我的 Angular 项目从版本6迁移到9,但在迁移至8时一切顺利并且它可以正常工作。但当我从v8迁移到v9时,我的项目在屏幕上变空了,而IVY在构建时没有显示任何错误,并且Chrome控制台也没有错误。我已经测试了测试组件并发现路由出口有效,但是在我的项目组件上,因为ivy会一次性编译所有代码,所以我无法获取受影响的区域包或代码进行调试。

提前致谢。

main.ts看起来像这样

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

tsconfig.json

   {
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

package.json

  {
  "name": "project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^9.0.4",
    "@angular/cdk": "^7.3.2",
    "@angular/common": "^9.0.4",
    "@angular/compiler": "^9.0.4",
    "@angular/core": "^9.0.4",
    "@angular/forms": "^9.0.4",
    "@angular/http": "^6.1.0",
    "@angular/localize": "^9.0.4",
    "@angular/material": "^7.3.2",
    "@angular/platform-browser": "^9.0.4",
    "@angular/platform-browser-dynamic": "^9.0.4",
    "@angular/router": "^9.0.4",
    "@ng-bootstrap/ng-bootstrap": "^5.x.x",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "@sentry/browser": "^5.11.0",
    "angular-file-uploader": "^4.1.4",
    "angular-ng-autocomplete": "^1.1.17",
    "angular2-signaturepad": "^2.8.0",
    "core-js": "^2.5.4",
    "jquery": "^3.3.1",
    "moment": "^2.24.0",
    "ng2-haversine": "^0.1.1",
    "ng2-uploader": "^2.0.0",
    "ngx-material-timepicker": "^2.12.0",
    "ngx-spinner": "^7.1.4",
    "ngx-ui-loader": "^7.2.2",
    "rxjs": "^6.5.3",
    "tslib": "^1.10.0",
    "typescript": "^3.6.4",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.4",
    "@angular/cli": "~9.0.4",
    "@angular/compiler-cli": "^9.0.4",
    "@angular/language-service": "^9.0.4",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/jquery": "^3.3.22",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.0.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.1",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

请您能否添加一些逗号,并发布相关的代码,例如 package.jsontsconfig、主模块和路由? - Jacopo Sciampi
是的,我已经在路由器中使用了所有逗号,每当我将路由组件更改为我的新创建的TestComponent时,路由工作正常,但我的项目代码重定向到路径匹配不起作用 { path: 'xx', component: xx},{ path: 'xx', component: xx, canActivate: [WorkflowGuard] }, { path: 'xx', component: xx, canActivate: [WorkflowGuard] }, { path: 'xx', component: xx}, { path: '', redirectTo: '/xx', pathMatch: 'full' }, { path: '**', redirectTo: '/xx'} - Abhishek Sharma
我是说在你的问题中应该使用逗号。另外,请将相关代码格式化后添加到你的问题中。 - Jacopo Sciampi
@JacopoSciampi,请在上方找到相关代码。 - Abhishek Sharma
1个回答

1

我仍然在使用新的IVY遇到问题。 当我使用ng build/serve --prod运行Angular8代码库时,它可以工作,但是在Angular9代码库中,只有ng server正在运行,当我添加--prod到serve或build时,它无法工作。 - Abhishek Sharma
我在Chrome上经常遇到错误polyfills.9b85908313a7766a001a.js:1 Unhandled Promise rejection: Angular JIT编译失败:未加载'@angular/compiler' 不建议在生产环境中使用JIT编译!请考虑使用AOT模式。 -您是否使用'@angular/platform-browser-dynamic'或'@angular/platform-server'引导? -或者在引导之前为编译器提供'import "@angular/compiler";'。;区域:<root>;任务:Promise.then;值:错误:Angular JIT编译失败:未加载'@angular/compiler' - Abhishek Sharma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接