You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行tns generate component movies时@nativescript/schematics报错求助

解决NativeScript Angular中tns generate component movies的两个常见错误

从你提供的配置和错误信息来看,问题的核心是Angular CLI版本与NativeScript Schematics版本不兼容,下面分步骤帮你解决这两个问题:

第一个错误:Could not find module "@nativescript/schematics"

这个错误是因为你的项目依赖Angular 9.x版本,但安装了Angular CLI 10.x,高版本CLI无法自动识别适配NativeScript 9.x的schematics包。解决步骤如下:

  1. 卸载当前不兼容的Angular CLI(全局+本地):
npm uninstall -g @angular/cli
npm uninstall @angular/cli --save-dev
  1. 安装与你的Angular 9.1.x匹配的CLI版本:
npm install -g @angular/cli@9.1.12
npm install @angular/cli@9.1.12 --save-dev
  1. 安装适配NativeScript Angular 9.x的schematics包:
npm install @nativescript/schematics@9.0.0 --save-dev

第二个错误:Error: Invalid rule result: Instance of class Promise

这个错误同样是版本不匹配导致的——Angular CLI 10的schematics规则返回格式与NativeScript 9.x的schematics不兼容。完成版本统一后,还需要确保Angular项目默认使用NativeScript的schematics:

在项目根目录的angular.json文件中,找到schematics节点(如果没有则添加),配置如下:

"schematics": {
  "@nativescript/schematics": {
    "component": {
      "styleext": "css"
    }
  }
}

如果你的angular.json中已有默认schematics配置,需要替换为NativeScript的,确保生成组件时使用正确的规则。

验证解决方案

完成上述步骤后,重新执行命令:

tns generate component movies

应该就能正常生成组件了。

补充说明

你的项目依赖中,@nativescript/angular是9.0.0版本,对应的Angular核心包都是9.1.x,必须保持Angular CLI和schematics的版本与Angular核心版本一致,才能避免跨版本的兼容性问题。

内容的提问来源于stack exchange,提问作者wiotrek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 18:02:55