Angular 4:无法使用Angular CLI生成新组件

时间:2017-10-10 00:26:55

标签: angular angular-cli

我想使用Angular CLI生成一个新组件。

但是,当我从我的应用根运行ng g component my-new-component时,出现以下错误:

feilan@feilan-kubuntu:/media/feilan/Data/devprojects/web/udemy-angular4/components101$ ng g c moduleName --module='app.module.shared.ts'
The command "generate" has an option without the required type and name fields.
Error: The command "generate" has an option without the required type and name fields.
    at Class.validateOption (/media/feilan/Data/devprojects/web/udemy-angular4/components101/node_modules/@angular/cli/ember-cli/lib/models/command.js:377:13)
    at Array.map (native)
    at Class.registerOptions (/media/feilan/Data/devprojects/web/udemy-angular4/components101/node_modules/@angular/cli/ember-cli/lib/models/command.js:163:27)
    at getOptionsTask.run.then (/media/feilan/Data/devprojects/web/udemy-angular4/components101/node_modules/@angular/cli/commands/generate.js:98:18)

我尝试过的替代品,没有成功:

  • ng generate
  • ng generate --force
  • src/src/app/
  • 运行命令

某些版本信息:

feilan@feilan-kubuntu:/media/feilan/Data/devprojects/web/udemy-angular4/components101$ ng -v
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.4.5
node: 6.11.4
os: linux x64
@angular/animations: 4.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/cli: 1.4.5
@angular/compiler-cli: 4.4.4
@angular/language-service: 4.4.4
typescript: 2.3.4

2 个答案:

答案 0 :(得分:1)

这对我有用。执行干净卸载并重新安装:

  1. 卸载角度: npm uninstall -g @ angular / cli

  2. 检查版本(确保已卸载):ng -v

    如果仍显示版本,则尚未安装角度。

    如果您的cmd显示'ng'未被识别为内部或外部命令,可运行的程序或批处理文件。它已成功卸载

  3. 使用以下方法重新安装: npm install -g @ angular / cli

  4. 重复步骤2以检查版本并使用ng new proj-name

答案 1 :(得分:0)

修复可以在这里找到delasteve的答案 https://github.com/angular/angular-cli/issues

重新安装CLI

npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli

全球包装:

npm uninstall -g @angular/cli
npm cache clean
# if npm version is > 5 then use `npm cache verify` to avoid errors (or to avoid using --force)
npm install -g @angular/cli@latest