【问题标题】:Nativescript error 'Cannot read property 'kind' of undefined' when run 'ng generate component'运行“ng 生成组件”时,Nativescript 错误“无法读取未定义的属性“种类”
【发布时间】:2021-01-21 22:42:52
【问题描述】:

我无法向我的 Nativescript 项目添加新组件,当我执行 ng generate component faqs 时它返回错误:

Option "entryComponent" is deprecated: Since version 9.0.0 with Ivy, entryComponents is no longer necessary.
Cannot read property 'kind' of undefined

或者如果我像 ng generate component 一样运行它,它会询问我组件名称

? What name would you like to use for the component? faqs

然后返回

Option "entryComponent" is deprecated: Since version 9.0.0 with Ivy, entryComponents is no longer necessary.
Cannot read property 'match' of undefined

我正在使用:

Nativescript 7.0.10

Angular CLI: 10.1.4
Node: 12.18.4
OS: win32 x64

Angular: 10.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1001.4
@angular-devkit/core         10.0.8
@angular-devkit/schematics   10.1.4
@ngtools/webpack             10.1.4
@schematics/angular          10.1.4
@schematics/update           0.1001.4
rxjs                         6.6.3
typescript                   3.9.7

然后我就跑了:

tns create HelloWorld
npm i --save-dev @angular/cli
npm install --save-dev @nativescript/schematics
npm install --save-dev @schematics/angular

【问题讨论】:

  • 你解决了吗?不支持 NativeScript 真的很烦人,即使是简单的事情,比如运行他们的演示项目并在全新安装的中断中创建一个组件,并且任何地方都没有文档。
  • 其实不是,我避而远之。我手动创建组件。

标签: angular typescript nativescript nativescript-angular


【解决方案1】:

根据https://github.com/NativeScript/nativescript-schematics/issues/302 的解决方案/解决方法是将打字稿更新到版本4,即运行

npm install --save-dev typescript@4

我测试了以下步骤,似乎可行:

npm i -g @nativescript/schematics
ng new -c=@nativescript/schematics my-project --shared
cd my-project
npm install --save-dev typescript@4
ng g component bla

【讨论】:

  • 我的意思是没有。现在我无法运行它。我明白了:stackoverflow.com/questions/63512218/… 解决方案是降级打字稿。我在这里陷入了无限循环。
  • @Andrej 你能提供更多关于你的设置的细节吗?我上面执行的步骤对我有用。你确定更新@angular-devkit/build-angular等吗?
  • 更新:我创建了新项目,按照您的步骤操作,但没有在全球范围内安装任何东西。现在可以了。
【解决方案2】:

错误主要与 Angular、Node、NPM 和 TypeScript 版本之间的冲突有关。在运行和编译时,我自己在一些较旧的 Angular 项目中看到了它。尽管 TypeScript 或 Angular github 问题都没有明确的答案,但以下是您可以减少冲突文件/文件夹并摆脱问题的许多方法:

  1. 删除node_modules和package-lock.json并重新安装模块
  2. 其中一个 Angular ngtools 版本有一个错误,这是导致问题的原因,并且是 fixed
  3. 项目中@angular/cli 的本地安装版本与@angular/cli 的全局安装版本不同。
  4. 在编译服务器运行时更​​改/替换文件,在这种情况下,在添加或删除文件之前停止编译器

除此之外,您还可以进一步阅读 Typescript 和 Angular 各自存储库中的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    相关资源
    最近更新 更多