【问题标题】:Angular2: Error while creating new component via CLIAngular2:通过 CLI 创建新组件时出错
【发布时间】:2017-02-08 04:55:55
【问题描述】:

使用 Angular2,在移入项目文件夹后,我在尝试通过 CLI 创建新组件时遇到此错误,我将发布所有终端消息:

edoardocanti$ ng generate component other
Could not start watchman; falling back to NodeWatcher for file system          
events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
installing component
create src/app/other/other.component.css
create src/app/other/other.component.html
create src/app/other/other.component.spec.ts
create src/app/other/other.component.ts
Cannot read property 'read' of undefined
TypeError: Cannot read property 'read' of undefined
at InsertChange.apply (/Users/edoardocanti/first-     
app/node_modules/@angular-cli/ast-tools/src/change.js:96:20)
at /Users/edoardocanti/first-app/node_modules/@angular-cli/ast-  
tools/src/change.js:71:61
at process._tickCallback (internal/process/next_tick.js:103:7) 

它创建了我的新组件的文件夹,但我必须在 app.module.ts 中手动添加它,但是它可以工作。

真正的问题是当我尝试在现有文件夹中创建新组件时,在这种情况下,Angular 不会创建任何新组件。

【问题讨论】:

  • 我也被这个问题困扰过,但是同样版本的 angular-cli 对我几天前创建的另一个项目也能正常工作

标签: angularjs macos angular terminal command-line-interface


【解决方案1】:

你在 angular-cli 的 1.0.0.beta15 上吗?如果是这样,npm install -g angular-cli@latest。这个问题似乎在 beta16 中消失了

【讨论】:

    【解决方案2】:

    确保您 cd 进入 app 文件夹(以防万一,从您的示例中看起来没有),如果没有,请尝试...

    检查版本并确保您是最新版本:

    ng -v
    angular-cli: 1.0.0-beta.16
    node: 6.2.0
    os: darwin x64
    

    删除旧的并安装新的:

    npm uninstall -g angular-cli
    npm remove cache
    npm install -g angular-cli@latest
    

    如果您有一个现有项目: 可能还需要删除 node_modules 到处寻找 beta.15 并替换为 beta.16

    更改 angular-cli.json: "version": "1.0.0-beta.16", 包.json: “开发依赖”:{ "angular-cli": "1.0.0-beta.16",

    【讨论】:

      猜你喜欢
      • 2017-04-20
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      相关资源
      最近更新 更多