简体   繁体   English

Angular 2 CLI升级到最新和现在的ng服务给我错误

[英]Angular 2 CLI Upgraded to latest and now ng serve gives me errors

I upgraded to 1.0.0-beta.11-webpack.8 in my current Angular 2 CLI project, as well as updating my angular-cli.json to match the expected properties of the upgraded CLI. 我在当前的Angular 2 CLI项目中升级到1.0.0-beta.11-webpack.8 ,以及更新我的angular-cli.json以匹配升级的CLI的预期属性。 When I run ng serve, I get this error: 当我运行服务时,我收到此错误:

`Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at Object.getWebpackCommonConfig (/Applications/MAMP/htdocs/learnloop/node_modules/angular-cli/addon/ng2/models/webpack-build-common.ts:23:25)
    at new NgCliWebpackConfig (/Applications/MAMP/htdocs/learnloop/node_modules/angular-cli/addon/ng2/models/webpack-config.ts:13:30)
    at Class.exports.default.Task.extend.run (/Applications/MAMP/htdocs/learnloop/node_modules/angular-cli/addon/ng2/tasks/serve-webpack.ts:19:22)
    at /Applications/MAMP/htdocs/learnloop/node_modules/angular-cli/addon/ng2/commands/serve.ts:84:26
    at process._tickCallback (internal/process/next_tick.js:103:7)`

I wrestled with this for awhile, but after running all of these commands and getting Angular CLI to not be in a broken state, I'm running into this issue. 我已经和它搏斗了一段时间,但是在运行所有这些命令并让Angular CLI处于不稳定状态之后,我遇到了这个问题。 Here are the commands I ran: 以下是我运行的命令:

`npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@webpack
rm -rf node_modules dist tmp typings
npm install --save-dev angular-cli@webpack`

And finally, here are the versions of node, npm, and Angular CLI that I'm running: 最后,这里是我正在运行的node,npm和Angular CLI的版本:

Node v6.4.0 NPM 3.10.3 angular-cli: 1.0.0-beta.11-webpack.8

And here is my angular-cli.json: 这是我的angular-cli.json:

`{
  "project": {
    "version": "1.0.0-beta.11-webpack.8",
    "name": "learnloop"
  },
  "apps": [
    {
      "main": "src/main.ts",
      "tsconfig": "src/tsconfig.json",
      "mobile": false,
      "prefix": "app",
      "root": "src",
      "styles": [
        "styles.scss"
      ]
    }
  ],
  "addons": [],
  "packages": [],
  "e2e": {
    "protractor": {
      "config": "config/protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "config/karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "prefixInterfaces": false,
    "lazyRoutePrefix": "+"
  }
}`

I apologize for the huuuuge wall of text, but I wanted to make sure you all had everything you needed to potentially help with this. 我为huuuuge文本墙道歉,但我想确保你们都拥有了所需的一切,可以为此提供帮助。 What am I doing wrong here? 我在这做错了什么?

I managed to get this to work. 我设法让这个工作。 Try pasting this into your angular-cli.json (edit it accordingly): 尝试将其粘贴到angular-cli.json中(相应地编辑它):

{
  "project": {
    "version": "1.0.0-beta.11-webpack.8",
    "name": "<name-of-app>"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": "assets",
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
      "styles": [
        "styles.scss"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "dev": "environments/environment.dev.ts"
      }
    }
  ],
  "addons": [],
  "packages": [],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "prefixInterfaces": false,
    "lazyRoutePrefix": "+"
  }
}

Then type ng init inside of root project directory. 然后在根项目目录中键入ng init It'll ask you to replace a bunch of different files or keep them. 它会要求你替换一堆不同的文件或保留它们。 There are some slight differences between files, particularly inside of app.module.ts so make sure you commit first, as there will be some changes in file structure and code inside of the files. 文件之间存在一些细微差别,特别是在app.module.ts内部,因此请确保先提交,因为文件结构和文件内部的代码会有一些变化。

Try updating your nodejs version to the latest (currently v.7.2). 尝试将nodejs版本更新为最新版本(目前为v.7.2)。 It worked for me with ng serve failing 它对我有用,因为服务失败了

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

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