无法在 Object.normalizeSlashes Angular CLI 读取未定义的 属性 'replace'

Cannot read property 'replace' of undefined at Object.normalizeSlashes Angular CLI

我之前研究了一些 post 但我没有找到解决我本周遇到的这个问题的方法,而我过去没有使用相同的代码。

我的问题出现在 VSTS - 托管代理上,我正在尝试在那里构建项目,它触发了这个错误,在尝试了我得到的所有想法之后,就在这里提问。

请注意,在我的机器上,在本地工作时,它运行完美。

我尝试过的一些事情是:

所以,这是 main.ts

/// <reference path="../typings/index.d.ts" />
require('core-js/shim');
require('zone.js/dist/zone');
require('reflect-metadata/temp/Reflect');

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
import { IEnvironment } from './_shared/entities/interfaces/index';
declare let environment: IEnvironment;

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

platformBrowserDynamic().bootstrapModule(AppModule);

这是简短的错误日志:

./src/app/main.ts
Module build failed: TypeError: Cannot read property 'replace' of undefined
  at Object.normalizeSlashes

这是很长的错误日志:

0% compiling 10% building modules 0/1 modules 1 active multi main            10% building modules 1/1 modules 0 active 10% building modules 1/2 modules 1 active multi styles              10% building modules 2/2 modules 0 active 10% building modules 2/3 modules 1 active multi scripts               10% building modules 3/3 modules 0 active 10% building modules 3/4 modules 1 active ...ode_modules\signalr\jquery.signalR.js                                          10% building modules 4/4 modules 0 active 10% building modules 4/5 modules 1 active ...node_modules\underscore\underscore.js                                          10% building modules 5/5 modules 0 active 10% building modules 5/6 modules 1 active ...\s\node_modules\jquery\dist\jquery.js                                          10% building modules 6/6 modules 0 active 10% building modules 6/7 modules 1 active ...odules\bootstrap\dist\js\bootstrap.js                                          10% building modules 7/7 modules 0 active 10% building modules 7/8 modules 1 active ...node_modules\tether\dist\js\tether.js                                          10% building modules 8/8 modules 0 active 10% building modules 8/9 modules 1 active ....js?sourcemap!C:\a\s\src\style.scss                                          11% building modules 9/9 modules 0 active 11% building modules 9/10 modules 1 active ...js?sourcemap!C:\a\s\src\vendor.scss                                         11% building modules 10/10 modules 0 active 11% building modules 10/11 modules 1 active ...s\font-awesome\scss\font-awesome.scss                                          11% building modules 11/11 modules 0 active 11% building modules 11/12 modules 1 active ...ode_modules\signalr\jquery.signalR.js 11% building modules 11/13 modules 2 active ...node_modules\underscore\underscore.js 11% building modules 11/14 modules 3 active ...\s\node_modules\jquery\dist\jquery.js 11% building modules 11/15 modules 4 active ...odules\bootstrap\dist\js\bootstrap.js 11% building modules 11/16 modules 5 active ...node_modules\tether\dist\js\tether.js 11% building modules 11/17 modules 6 active ....js?sourcemap!C:\a\s\src\style.scss 11% building modules 11/18 modules 7 active ...js?sourcemap!C:\a\s\src\vendor.scss 11% building modules 11/19 modules 8 active ...s\font-awesome\scss\font-awesome.scss 11% building modules 11/20 modules 9 active ...src\index.js!C:\a\s\src\app\main.ts 11% building modules 11/21 modules 10 active ...de_modules\script-loader\addScript.js 11% building modules 11/22 modules 11 active ...ode_modules\style-loader\addStyles.js 11% building modules 12/22 modules 10 active ...ode_modules\style-loader\addStyles.js  11% building modules 13/22 modules 9 active ...ode_modules\style-loader\addStyles.js 11% building modules 14/22 modules 8 active ...ode_modules\style-loader\addStyles.js 11% building modules 15/22 modules 7 active ...ode_modules\style-loader\addStyles.js 11% building modules 16/22 modules 6 active ...ode_modules\style-loader\addStyles.js 12% building modules 17/22 modules 5 active ...ode_modules\style-loader\addStyles.js 12% building modules 18/22 modules 4 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 19/22 modules 3 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 20/22 modules 2 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 20/23 modules 3 active ...de_modules\css-loader\lib\css-base.js 12% building modules 21/23 modules 2 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 22/23 modules 1 active ...js?sourcemap!C:\a\s\src\vendor.scss 12% building modules 22/24 modules 2 active ...fonts\fontawesome-webfont.eot?v=4.7.0 12% building modules 22/25 modules 3 active ...awesome\fonts\fontawesome-webfont.eot 12% building modules 22/26 modules 4 active ...fonts\fontawesome-webfont.svg?v=4.7.0 12% building modules 22/27 modules 5 active ...nts\fontawesome-webfont.woff2?v=4.7.0 12% building modules 22/28 modules 6 active ...onts\fontawesome-webfont.woff?v=4.7.0 12% building modules 22/29 modules 7 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 12% building modules 23/29 modules 6 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 12% building modules 24/29 modules 5 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 25/29 modules 4 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 26/29 modules 3 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 27/29 modules 2 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 28/29 modules 1 active ...js?sourcemap!C:\a\s\src\vendor.scss                                          13% building modules 29/29 modules 0 active 13% building modules 29/30 modules 1 active ...\node_modules\animate.css\animate.css                                          13% building modules 30/30 modules 0 active                                 71% sealing 72% optimizing 73% basic module optimization       74% module optimization 75% advanced module optimization     76% basic chunk optimization 76% basic chunk optimization pass 2 76% basic chunk optimization pass 3              77% chunk optimization 78% advanced chunk optimization 79% module and chunk tree optimization                    80% module reviving 81% module order optimization    82% module id optimization         83% chunk reviving 84% chunk order optimization    85% chunk id optimization               86% hashing 87% module assets processing  88% chunk assets processing 89% additional chunk assets processing                          90% recording 91% additional asset processing    92% chunk asset optimization       94% asset optimization           95% emitting             Hash: [1m0afac734d2396ef89b20[39m[22m
2016-12-08T17:37:42.0619446Z Time: [1m9032[39m[22mms
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m0[39m[22m} [1m[32mstyles.bundle.js, styles.bundle.map[39m[22m (styles) 290 kB {[1m[33m3[39m[22m}[1m[33m [initial][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m1[39m[22m} [1m[32mscripts.bundle.js, scripts.bundle.map[39m[22m (scripts) 649 kB {[1m[33m3[39m[22m}[1m[33m [initial][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m2[39m[22m} [1m[32mmain.bundle.js, main.bundle.map[39m[22m (main) 2.54 kB[1m[33m [initial][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m3[39m[22m} [1m[32minline.bundle.js, inline.bundle.map[39m[22m (inline) 0 bytes[1m[33m [entry][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z 
2016-12-08T17:37:42.0619446Z [1m[31mERROR in ./src/app/main.ts
2016-12-08T17:37:42.0619446Z Module build failed: TypeError: Cannot read property 'replace' of undefined
2016-12-08T17:37:42.0619446Z     at Object.normalizeSlashes (C:\a\s\node_modules\typescript\lib\typescript.js:1771:20)
2016-12-08T17:37:42.0619446Z     at writeReferencePath (C:\a\s\node_modules\typescript\lib\typescript.js:37236:90)
2016-12-08T17:37:42.0619446Z     at C:\a\s\node_modules\typescript\lib\typescript.js:35750:29
2016-12-08T17:37:42.0629440Z     at Object.forEach (C:\a\s\node_modules\typescript\lib\typescript.js:1115:30)
2016-12-08T17:37:42.0629440Z     at C:\a\s\node_modules\typescript\lib\typescript.js:35742:20
2016-12-08T17:37:42.0629440Z     at Object.forEach (C:\a\s\node_modules\typescript\lib\typescript.js:1115:30)
2016-12-08T17:37:42.0629440Z     at emitDeclarations (C:\a\s\node_modules\typescript\lib\typescript.js:35735:12)
2016-12-08T17:37:42.0629440Z     at getDeclarationDiagnosticsFromFile (C:\a\s\node_modules\typescript\lib\typescript.js:35699:13)
2016-12-08T17:37:42.0629440Z     at onSingleFileEmit (C:\a\s\node_modules\typescript\lib\typescript.js:7569:13)
2016-12-08T17:37:42.0629440Z     at Object.forEachExpectedEmitFile (C:\a\s\node_modules\typescript\lib\typescript.js:7542:21)
2016-12-08T17:37:42.0629440Z     at Object.getDeclarationDiagnostics (C:\a\s\node_modules\typescript\lib\typescript.js:35695:12)
2016-12-08T17:37:42.0629440Z     at C:\a\s\node_modules\typescript\lib\typescript.js:45673:27
2016-12-08T17:37:42.0629440Z     at runWithCancellationToken (C:\a\s\node_modules\typescript\lib\typescript.js:45468:24)
2016-12-08T17:37:42.0629440Z     at getDeclarationDiagnosticsWorker (C:\a\s\node_modules\typescript\lib\typescript.js:45669:20)
2016-12-08T17:37:42.0629440Z     at getDeclarationDiagnosticsForFile (C:\a\s\node_modules\typescript\lib\typescript.js:45677:60)
2016-12-08T17:37:42.0629440Z     at getDiagnosticsHelper (C:\a\s\node_modules\typescript\lib\typescript.js:45436:24)
2016-12-08T17:37:42.0629440Z     at Object.getDeclarationDiagnostics (C:\a\s\node_modules\typescript\lib\typescript.js:45460:24)
2016-12-08T17:37:42.0629440Z     at TypeScriptFileRefactor.getDiagnostics (C:\a\s\node_modules\@ngtools\webpack\src\refactor.js:51:35)
2016-12-08T17:37:42.0629440Z     at _checkDiagnostics (C:\a\s\node_modules\@ngtools\webpack\src\loader.js:106:32)
2016-12-08T17:37:42.0629440Z     at C:\a\s\node_modules\@ngtools\webpack\src\loader.js:140:17
2016-12-08T17:37:42.0629440Z     at tryCatch (C:\a\s\node_modules\es6-promise\dist\es6-promise.js:410:12)
2016-12-08T17:37:42.0629440Z     at invokeCallback (C:\a\s\node_modules\es6-promise\dist\es6-promise.js:425:13)
2016-12-08T17:37:42.0629440Z     at publish (C:\a\s\node_modules\es6-promise\dist\es6-promise.js:393:7)
2016-12-08T17:37:42.0629440Z     at flush (C:\a\s\node_modules\es6-promise\dist\es6-promise.js:121:5)
2016-12-08T17:37:42.0629440Z     at _combinedTickCallback (internal/process/next_tick.js:67:7)
2016-12-08T17:37:42.0629440Z     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-12-08T17:37:42.0629440Z  @ multi main[39m[22m

编辑。添加... Package.json

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "src/app/main.ts",
  "scripts": {
    "build": "ng build",
    "start": "ng serve --host 0.0.0.0 --port 8080 --live-reload-port 49153",
    "dev": "ng build && npm start",
    "lint": "tslint --project ./tslint.json",
    "test": "ng test --watch=false",
    "postinstall": "gulp delete:types",
    "compile-ts": "node node_modules/typescript/lib/tsc.js -p ./tsconfig.json",
    "compile-sass": "gulp sass-compiler",
    "compile": "npm run compile-ts && npm run compile-sass",
    "clean": "gulp delete",
    "zip": "gulp zip"
  },
  "author": "me",
  "license": "MIT",
  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.14",
    "angular-cli": "^1.0.0-beta.18",
    "animate.css": "^3.5.2",
    "bootstrap": "^4.0.0-alpha.4",
    "core-js": "^2.4.1",
    "font-awesome": "^4.6.3",
    "jquery": "^3.1.1",
    "karma-phantomjs-launcher": "^1.0.2",
    "ng2-pagination": "^0.5.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "signalr": "^2.2.1",
    "systemjs": "0.19.39",
    "underscore": "^1.8.3",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "codelyzer": "^1.0.0-beta.4",
    "del": "^2.2.1",
    "gulp": "^3.9.1",
    "gulp-fail": "^1.0.5",
    "gulp-sass": "^2.3.2",
    "gulp-zip": "^3.0.2",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "ts-node": "1.2.1",
    "tslint": "3.15.1",
    "typescript": "~2.0.3",
    "typings": "^1.4.0"
  }
}

我刚刚在 angular-cli 存储库上创建了一个请求来询问这个问题,并且确实意识到我在 [=21] 上的 angular-cli 版本中使用了插入符号“^” =],这意味着我没有使用我相信的版本。

我删除并强制使用那个 1.0.0-beta.18,它现在可以工作了。

不过,我不明白为什么它不能在 VSTS 上使用较新的版本,而在本地可以使用,但对我来说,这个解决方法是有效的。

这是我创建的工单,以防万一你想看看它可能对其他人有帮助。

https://github.com/angular/angular-cli/issues/3491

我偶然发现了这个 post 因为我得到的错误是这样的:

Module build failed: TypeError: Cannot read property 'replace' of undefined

(我的错误和我的项目与 OP 的问题甚至没有模糊关系)

我的错误是我也在我的 WSL 中安装了 node 和 npm,这与 windows 中的安装产生了冲突。我按照 从 ubuntu 中删除了节点和 npm(它们仍然安装在 windows 上),现在一切正常。