重新安装angular / cli之后:模块构建失败:TypeError:无法读取未定义的属性'newLine'

时间:2017-10-25 09:53:16

标签: javascript angularjs typescript npm angular-cli

我有一个angular-2应用程序。

我尝试运行ng serve,但收到此错误:

ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/Users/eladb/WorkspaceQa/Gasolina/node_modules/typescript/lib/typescript.js:8062:20)
    at Object.createCompilerHost (/Users/eladb/WorkspaceQa/Gasolina/node_modules/typescript/lib/typescript.js:44978:26)
    at Object.ngcLoader (/Users/eladb/WorkspaceQa/Gasolina/node_modules/@ngtools/webpack/src/loader.js:170:31)
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

ERROR in ./src/polyfills.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/Users/eladb/WorkspaceQa/Gasolina/node_modules/typescript/lib/typescript.js:8062:20)
    at Object.createCompilerHost (/Users/eladb/WorkspaceQa/Gasolina/node_modules/typescript/lib/typescript.js:44978:26)
    at Object.ngcLoader (/Users/eladb/WorkspaceQa/Gasolina/node_modules/@ngtools/webpack/src/loader.js:170:31)
 @ multi ./src/polyfills.ts
webpack: Failed to compile.

我尝试在本地和全局卸载并重新安装angular / cli。

但我仍然会收到此错误。

这是我的package.json

{
  "name": "x",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "posttest": "node_modules/.bin/remap-istanbul -i coverage/coverage.json -o coverage/html-report -t html",
    "coverage": "http-server -c-1 -o -p 9876 ./coverage"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.7",
    "@angular/compiler": "^2.4.7",
    "@angular/core": "^2.4.7",
    "@angular/forms": "^2.4.7",
    "@angular/http": "^2.4.7",
    "@angular/material": "^2.0.0-beta.2",
    "@angular/platform-browser": "^2.4.7",
    "@angular/platform-browser-dynamic": "^2.4.7",
    "@angular/router": "^3.4.7",
    "ng2-tabs": "^0.0.11",
    "core-js": "^2.4.1",
    "ng2-bootstrap": "^1.3.3",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0-rc.1",
    "@angular/compiler-cli": "^2.4.7",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "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-coverage": "^1.1.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "remap-istanbul": "^0.9.5",
    "karma-istanbul-threshold": "^1.2.2",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.3"
  }
}

1 个答案:

答案 0 :(得分:0)

您使用的是哪个版本的CLI?这一切看起来都过时了

这可能有所帮助:

npm uninstall -g angular-cli
npm install -g @angular/cli

官方文档:https://cli.angular.io/

然后,生成新项目:ng new myapp