【问题标题】:AngularCli & AOT: ERROR Error: Runtime compiler is not loadedAngularCli & AOT:ERROR 错误:未加载运行时编译器
【发布时间】:2017-10-15 21:07:18
【问题描述】:

我正在尝试使用 Ahead of Time 构建我的 Angular4 应用程序。 构建过程运行良好且没有错误,但是当我运行应用程序时,我在控制台中收到此错误:

ERROR Error: Runtime compiler is not loaded
    at J (vendor.ac8dafb82366354245dd.bundle.js:1)
    at t.compileModuleSync (vendor.ac8dafb82366354245dd.bundle.js:1)
    at t.QFu1.t.createDynamicTemplate (vendor.ac8dafb82366354245dd.bundle.js:1)
    at t.QFu1.t.ngDoCheck (vendor.ac8dafb82366354245dd.bundle.js:1)
    at xn (vendor.ac8dafb82366354245dd.bundle.js:1)
    at pr (vendor.ac8dafb82366354245dd.bundle.js:1)
    at cr (vendor.ac8dafb82366354245dd.bundle.js:1)
    at Yr (vendor.ac8dafb82366354245dd.bundle.js:1)
    at Object.updateDirectives (vendor.ac8dafb82366354245dd.bundle.js:1)
    at Object.updateDirectives (vendor.ac8dafb82366354245dd.bundle.js:1)
b @ vendor.ac8dafb82366354245dd.bundle.js:1
vendor.ac8dafb….bundle.js:1 WebSocket connection to 'ws://null/algorilla/ws/websocket/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED
r @ vendor.ac8dafb….bundle.js:1

该应用程序是可导航的,但没有任何功能可以正常工作! 我做错了什么?为什么编译后的代码会引用运行时编译器?

我不使用任何角度/编译组件或服务。

在我的组件中,我以这种方式引用服务模拟:

@Component({
  selector: 'app-authorization',
  templateUrl: './authorization.component.html',
  providers: [
    { provide: SecurityService, useClass: (environment.mock ? SecurityServiceMock : SecurityService) }
  ]
})

如果 var "environment.mock" 为真,我使用 SecurityServiceMock,否则使用真正的 SecurityService。

这可能是问题吗?

这是 tsconfig.json:

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

tsconfig.app.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

package.json:

{
  "name": "xxx",
  "version": "0.9.6",
  "description": "xxx",
  "author": "",
  "url": "xxx",
  "copyright": "xxx",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "4.4.3",
    "@angular/common": "4.4.3",
    "@angular/core": "4.4.3",
    "@angular/forms": "4.4.3",
    "@angular/http": "4.4.3",
    "@angular/platform-browser": "4.4.3",
    "@angular/platform-browser-dynamic": "4.4.3",
    "@angular/router": "4.4.3",
    "@angular/upgrade": "4.4.3",
    "@stomp/ng2-stompjs": "^0.4.2",
    "@types/highcharts": "^4.2.57",
    "@types/node": "^7.0.43",
    "@types/sockjs-client": "^1.0.32",
    "angular2-busy": "^2.0.4",
    "angular2-csv": "^0.2.5",
    "angular2-notifications": "^0.7.7",
    "angular2-prettyjson": "2.0.5",
    "angular2-websocket-service": "^0.5.3",
    "angular2gridster": "^0.6.7",
    "core-js": "2.4.1",
    "font-awesome": "^4.7.0",
    "highcharts": "^4.2.7",
    "js-beautify": "1.7.3",
    "moment": "2.18.1",
    "ng2-daterangepicker": "^2.0.7",
    "ng2-highcharts": "^1.0.0",
    "ng2-stomp-service": "^1.2.2",
    "ngx-bootstrap": "2.0.0-beta.6",
    "ngx-contextmenu": "^1.3.5",
    "ngx-cookie": "^1.0.0",
    "ngx-loading": "^1.0.5",
    "queueing-subject": "^0.1.1",
    "roboto-fontface": "^0.8.0",
    "roboto-mono-webfont": "^2.0.986",
    "rxjs": "5.4.1",
    "simple-line-icons": "^2.4.1",
    "sockjs-client": "^1.1.4",
    "stompjs": "^2.3.3",
    "t-json-viewer": "^1.2.0",
    "ts-helpers": "1.1.2",
    "typescript": "^2.4.0",
    "typings": "^2.1.1",
    "underscore": "^1.8.3",
    "vkbeautify": "0.99.3",
    "zone.js": "0.8.11"
  },
  "devDependencies": {
    "@angular/cli": "1.5.0-rc.0",
    "@angular/compiler-cli": "4.4.3",
    "@types/jasmine": "2.5.47",
    "@types/node": "^7.0.22",
    "codelyzer": "3.0.1",
    "jasmine-core": "2.6.2",
    "jasmine-spec-reporter": "4.1.0",
    "karma": "1.7.0",
    "karma-chrome-launcher": "2.1.1",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.2.1",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.2",
    "ts-node": "3.0.4",
    "tslint": "5.3.2",
    "typescript": "2.4.0"
  }
}

【问题讨论】:

  • 是的,但我的模块中没有声明任何 COMPILER_PROVIDERS
  • 请添加您的 package.json。您使用的是哪些库?
  • 很多。更新了帖子
  • 在您的代码中查找 createDynamicTemplate 方法。它可以在 node_modules 内

标签: angular angular2-aot


【解决方案1】:

您正在使用Compiler 服务中的compileModuleSync,该服务由createDynamicTemplate 方法调用。 Angular 编译器 cli 正在分析您的代码,并从您的模板和类(ngFactory 文件)创建 metadata,并在使用 AOT 时从您的应用程序中完全删除编译器模块。

如果您想使用 AOT,请不要使用 angular/compiler 包中的任何服务或方法。

您能否将 package.json 文件添加到您的答案中,可能存在未准备好 AOT 的第 3 方库。


网站注释: 你嘲笑你的服务的方式看起来有点奇怪,你可以只提供服务,然后在environment.mock ist true 时覆盖它。例如:

let myProviders = [
  SecurityService
];

if(environment.mock) {
  myProviders.push(
    { provide: SecurityService, useClass: SecurityServiceMock }
  )
}

// ...

providers: [
  ...myProviders
]

但这不是Runtime compiler is not loaded 错误的原因。

更新:

我发现错误是由您使用的angular2-busy 包引起的。

【讨论】:

  • 在我的组件中,我以这种方式模拟服务:@Component({ selector: 'app-authorization', templateUrl: './authorization.component.html', providers: [ { provide: SecurityService , useClass: (environment.mock ? SecurityServiceMock : SecurityService) }, { provide: DashboardManagerService, useClass: (environment.mock ? DashboardManagerServiceMock : DashboardManagerService) } ] }) 可能是问题所在?
  • 将相关代码添加到您的答案中,我们可以帮助您准备好 AOT。在您的代码中的某处,您正在使用 compileModuleSync 方法或调用它的某个方法。
  • 您能否也添加package.json 文件?
【解决方案2】:

这是关于 WebSocket url 检查它在你的代码中看到它。

到 'ws://null/algorilla/ws/websocket/' 的 WebSocket 连接失败:连接建立错误:net::ERR_NAME_NOT_RESOLVED

你有一个路径变量,它被设置为 null ;)

【讨论】:

  • 这不是问题。该消息是由在 AOT 编译的应用程序中使用编译器服务导致的 runtime compiler is not loaded 错误引起的。
  • 不,这是另一个问题,与“未加载运行时编译器”错误无关
【解决方案3】:

正如 cmets 中的@cyrix 所建议的那样,我在 nodeModules 中搜索了 compileModuleSync,并且找到了一个使用 angular 编译器的外部组件。

外部模块是 angular2-busy。

删除它解决了问题!

【讨论】:

  • 是的,这也是我发现的,只是将其添加到我的答案中。
猜你喜欢
  • 2019-07-08
  • 1970-01-01
  • 2021-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-27
  • 1970-01-01
  • 2010-12-11
相关资源
最近更新 更多