Aot ng build in Angular 4

时间:2017-10-30 19:16:27

标签: angular aot

我的角色4中的编译有问题,这是我的package.json:

  "dependencies": {
    "@agm/core": "1.0.0-beta.0",
    "@angular/animations": "4.4.6",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/compiler-cli": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "4.4.6",
    "@angular/platform-browser": "4.4.6",
    "@angular/platform-browser-dynamic": "4.4.6",
    "@angular/platform-server": "4.4.6",
    "@angular/router": "4.4.6",
    "@types/iban": "0.0.28",
    "core-js": "2.4.1",
    "dialog-polyfill": "0.4.7",
    "enhanced-resolve": "3.3.0",
    "font-awesome": "4.7.0",
    "iban": "0.0.8",
    "material-design-lite": "1.3.0",
    "modernizr": "3.5.0",
    "moment": "2.18.1",
    "raven-js": "3.12.1",
    "rxjs": "5.0.1",
    "ts-helpers": "1.1.1",
    "typescript": "^2.3.4",
    "web-animations-js": "2.2.2",
    "zone.js": "^0.8.4"
  },

      "devDependencies": {
        "@angular/cli": "^1.4.9",
        "@angular/compiler-cli": "4.4.6",
        "@ngtools/webpack": "1.7.4",
        "@angular/language-service": "4.4.6",
        "@types/core-js": "0.9.35",
        "@types/jasmine": "2.5.38",
        "@types/node": "6.0.42",
        "chai": "3.5.0",
        "chai-as-promised": "6.0.0",
        "chai-colors": "1.0.1",
        "codelyzer": "~2.0.0-beta.1",
        "compodoc": "0.0.32",
        "cucumber": "1.3.3",
        "cucumber-assert": "2.0.0",
        "cucumber-html-report": "0.5.9",
        "cucumber-junit-reporter": "git://github.com/davidparsson/cucumber-junit-reporter.git",
        "cucumberjs-junitxml": "1.0.0",
        "jasmine-core": "2.5.2",
        "jasmine-spec-reporter": "2.5.0",
        "karma": "1.2.0",
        "karma-chrome-launcher": "2.0.0",
        "karma-cli": "1.0.1",
        "karma-firefox-launcher": "1.0.1",
        "karma-jasmine": "1.0.2",
        "karma-phantomjs-launcher": "1.0.4",
        "karma-remap-istanbul": "0.2.1",
        "protractor": "~5.1.2",
        "protractor-cucumber-framework": "3.1.0",
        "ts-node": "1.2.1",
        "tslint": "4.0.2",
        "typescript": "^2.1.5"
      }

当我启动命令“ng build --aot”时,我遇到了这个错误:

looking for modules in /Users/raph/app/project/src
            using description file: /Users/raph/app/project/package.json (relative path: ./src)
              Field 'browser' doesn't contain a valid alias configuration
            after using description file: /Users/raph/app/project/package.json (relative path: ./src)
              using description file: /Users/raph/app/project/package.json (relative path: ./src/@angular/router/testing/src/router_testing_module)
                no extension
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/raph/app/project/src/@angular/router/testing/src/router_testing_module doesn't exist
                .ts
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/raph/app/project/src/@angular/router/testing/src/router_testing_module.ts doesn't exist
                .js
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/raph/app/project/src/@angular/router/testing/src/router_testing_module.js doesn't exist
                as directory
                  /Users/raph/app/project/src/@angular/router/testing/src/router_testing_module doesn't exist
    [/Users/raph/app/project/src/$$_gendir/app/core-module/node_modules]
    [/Users/raph/app/project/src/$$_gendir/app/node_modules]
    [/Users/raph/app/project/src/node_modules]
    [/Users/raph/app/node_modules]
    [/Users/raph/node_modules]
    [/Users/node_modules]
    [/node_modules]
    [/Users/raph/app/project/node_modules/@angular/router/testing/src/router_testing_module]
    [/Users/raph/app/project/node_modules/@angular/router/testing/src/router_testing_module.ts]
    [/Users/raph/app/project/node_modules/@angular/router/testing/src/router_testing_module.js]
    [/Users/raph/app/webapp/node_modules/@angular/router/testing/src/router_testing_module]

也许这是我的package.json中的配置问题或者我的文件中包含的问题,我在尝试调试时找不到一些东西。

只有在使用AOT模式构建时才会出现此错误。

1 个答案:

答案 0 :(得分:1)

看起来你也可能用你的构建来打包你的单元测试。我之所以这么说是因为我看到你的堆栈跟踪中引用了router_testing_module。这让我相信你要么:

  • 包括spec(测试)文件,但不要将其全部排除在tsconfig.json文件中。
  • 引用生产代码/模块中的spec(测试)文件