简体   繁体   English

使用AOT编译来编译Angle 4项目

[英]Compiling angular 4 project using AOT compilation

I am using angular 4 along with Webpack and Yarn as a package manager and ngrx-store. 我正在使用angular 4以及Webpack和Yarn作为包管理器和ngrx-store。 Started my project using JIT and trying to move to AOT. 使用JIT开始我的项目,并尝试移至AOT。 I keep getting all kind of errors which I am solving one by one, but maybe I am missing something here ... 我不断遇到各种各样的错误,我正在一步一步地解决它,但也许我在这里遗漏了一些东西...

Error: 错误:

ERROR in Error encountered resolving symbol values statically. ERROR中的ERROR遇到静态解析符号值的错误。 Function calls are not supported. 不支持函数调用。 Consider replacing the function or lambda with a reference to an exported function (position 12:42 in the original .ts file), resolving symbol compose in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/node_modules/@ngrx/core/src/compose.d.ts, resolving symbol compose in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/node_modules/@ngrx/core/index.d.ts, resolving symbol appReducer in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app_state.ts, resolving symbol appReducer in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app_state.ts, resolving symbol appReducer in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app_state.ts, resolving symbol AppModule in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app.module.ts, resolving symbol AppModule in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app.module.ts, resolving symbol AppModule 考虑使用对已导出函数的引用(原始.ts文件中的位置12:42)替换该函数或lambda,解决/ Users / doroneshel-mbp / development / yotpo-workspace / yotpo-install / node_modules / @中的符号撰写ngrx / core / src / compose.d.ts,在/Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/node_modules/@ngrx/core/index.d.ts中解析符号组成,在以下位置解析符号appReducer /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app_state.ts,解析/ Users / doroneshel-mbp / development / yotpo-workspace / yotpo-install / src / app /中的符号appReducer app_state.ts,在/Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app_state.ts中解析符号appReducer,在/ Users / doroneshel-mbp / development / yotpo-workspace /中解析符号AppModule yotpo-install / src / app / app.module.ts,解析符号/Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app.module.ts中的符号AppModule in /Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app.module.ts 在/Users/doroneshel-mbp/development/yotpo-workspace/yotpo-install/src/app/app.module.ts中

package.json : package.json

{
  "name": "app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "clean": "rimraf node_modules doc dist && npm cache clean",
    "clean-install": "npm run clean && npm install",
    "clean-start": "npm run clean-install && npm start",
    "watch": "webpack --watch --progress --profile",
    "build": "rimraf dist && webpack --progress --profile --bail",
    "server": "webpack-dev-server --inline --progress --port 8080",
    "webdriver-update": "webdriver-manager update",
    "webdriver-start": "webdriver-manager start",
    "lint": "tslint --force \"src/**/*.ts\"",
    "e2e": "protractor",
    "e2e-live": "protractor --elementExplorer",
    "pretest": "npm run lint",
    "test": "karma start",
    "posttest": "remap-istanbul -i coverage/json/coverage-final.json -o coverage/html -t html",
    "test-watch": "karma start --no-single-run --auto-watch",
    "ci": "npm run e2e && npm run test",
    "docs": "typedoc --options typedoc.json src/app/app.component.ts",
    "start": "npm run server",
    "start:hmr": "npm run server -- --hot",
    "postinstall": "npm run webdriver-update"
  },
  "dependencies": {
    "@angular/animations": "4.2.2",
    "@angular/common": "4.2.2",
    "@angular/compiler": "4.2.2",
    "@angular/compiler-cli": "4.2.2",
    "@angular/core": "4.2.2",
    "@angular/forms": "4.2.2",
    "@angular/http": "4.2.2",
    "@angular/platform-browser": "4.2.2",
    "@angular/platform-browser-dynamic": "4.2.2",
    "@angular/router": "4.2.2",
    "@ngrx/core": "^1.2.0",
    "@ngrx/effects": "^2.0.3",
    "@ngrx/store": "^2.2.2",
    "@ngtools/webpack": "^1.6.2",
    "@ngx-translate/core": "^7.0.0",
    "@ngx-translate/http-loader": "0.0.3",
    "@types/lodash": "^4.14.65",
    "angular2-ui-switch": "git+https://github.com/daominhsangvn/angular2-ui-switch",
    "bootstrap": "3.3.7",
    "core-js": "^2.4.1",
    "enhanced-resolve": "^3.4.1",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "karma-phantomjs-launcher": "^1.0.4",
    "ng-select": "^1.0.0-beta.6",
    "ng2-toastr": "^4.1.0",
    "ngx-bootstrap": "^1.7.1",
    "ngx-clipboard": "^8.0.4",
    "ngx-color-picker": "^4.0.3",
    "opensans-npm-webfont": "^0.0.2",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^5.0.1",
    "zone.js": "^0.8.5"
  },
  "devDependencies": {
    "@angularclass/hmr": "^1.0.1",
    "@angularclass/hmr-loader": "^3.0.2",
    "@types/jasmine": "^2.5.41",
    "@types/node": "^6.0.38",
    "@types/selenium-webdriver": "2.53.39",
    "angular-router-loader": "^0.6.0",
    "angular2-template-loader": "^0.6.0",
    "autoprefixer": "^6.3.2",
    "awesome-typescript-loader": "^3.1.3",
    "codelyzer": "2.0.0",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.4",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^0.11.2",
    "html-loader": "^0.4.0",
    "html-webpack-plugin": "^2.28.0",
    "istanbul-instrumenter-loader": "^2.0.0",
    "jasmine-core": "^2.3.4",
    "jasmine-spec-reporter": "^3.2.0",
    "json-loader": "^0.5.4",
    "karma": "1.4.1",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.0.0",
    "karma-jasmine": "^1.0.2",
    "karma-mocha-reporter": "^2.0.3",
    "karma-remap-istanbul": "0.2.1",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "2.0.2",
    "node-sass": "^4.5.0",
    "null-loader": "^0.1.1",
    "postcss-loader": "^1.1.0",
    "protractor": "^4.0.10",
    "raw-loader": "^0.5.1",
    "remap-istanbul": "^0.6.4",
    "resolve-url-loader": "^2.1.0",
    "rimraf": "^2.5.1",
    "sass-loader": "^6.0.6",
    "shelljs": "^0.7.0",
    "style-loader": "^0.18.2",
    "ts-helpers": "^1.1.1",
    "tslint": "^4.3.1",
    "tslint-loader": "^3.5.3",
    "typedoc": "^0.5.1",
    "typescript": "2.3.4",
    "url-loader": "^0.5.9",
    "webpack": "^3.3.0",
    "webpack-dev-server": "^2.5.0"
  }
}

tsconfig.json: tsconfig.json:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noEmitHelpers": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "lib": ["es2015", "dom"]
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  }
}

Followed this guide to make it all work : https://medium.com/@laco0416/aot-compilation-with-webpack-359ac9f4916f 遵循本指南进行操作: https : //medium.com/@laco0416/aot-compilation-with-webpack-359ac9f4916f

The problem was that I tried to export a const as a pointer to a function and it doesn't accept it for some reason. 问题是我试图将const导出为指向函数的指针,由于某种原因它不接受它。 changed it from export const -> export function with minor function changes. 从export const-> export function对其进行了更改,并进行了较小的功能更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM