Angular Nativescript如何修复ng g c上的错误?

Angular Nativescript how to fix error on ng g c?

之前,我创建了带有angular-nativescript的项目。安装后,我只使用了文档中的命令,尝试运行以下命令:

1
ng generate component home

我收到此错误:

An unhandled exception occurred: Cannot find module
'@schematics/angular/utility/parse-name' See
"C:\\Users\\andri\\AppData\\Local\\Temp\
g-JFv0M5\\angular-errors.log" for
further details.

更多详细信息:

[error] Error: Cannot find module
'@schematics/angular/utility/parse-name'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (C:\\Users\\andri\\AppData\
oaming\
pm\
ode_modules@nativescript\\schematics\\src\\generate\\component\\index.js:6:22)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)

该如何解决?

我的信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
√ Component nativescript has 6.0.3 version and is up to date.
√ Component tns-core-modules has 6.0.7 version and is up to date.
√ Component tns-android has 6.0.2 version and is up to date.
√ Component tns-ios has 6.0.2 version and is up to date.

Angular CLI: 8.3.0
Node: 10.15.3
Angular: 8.2.3
@angular-devkit/architect    0.803.0 (cli-only)
@angular-devkit/core         8.2.2
@angular-devkit/schematics   8.3.0
@ngtools/webpack             8.2.2
@schematics/angular          8.3.0
@schematics/update           0.803.0 (cli-only)
rxjs                         6.5.2
typescript                   3.5.3
webpack                      4.27.1

我对Nativescript的ng g有类似的问题,所以也许对某人有帮助

可能的错误:

1
2
3
An unhandled exception occurred: Could not find module"@nativescript/schematics" from
An unhandled exception occurred: Cannot find module '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript'
An unhandled exception occurred: Cannot find module 'tslint'

对于tns --version6.3.3

缺少以下依赖项:@nativescript/schematics @schematics/angular tslint

要使其运行,请运行:

1
npm i -D @nativescript/schematics @schematics/angular tslint


这对我有用:

1
2
3
4
5
npm i -D @nativescript/schematics

npm i -D @angular/cli

ng g c test

我这样做了:

npm install -g @schematics/angular

这为我解决了这个问题。


尝试一下,

npm卸载-g @ angular / cli

然后,

npm install -g @ angular / cli


以下内容对我有用:

  • 使用以下命令安装最新版本的cli:

    1
     npm install -g @angular/cli"
  • 从项目中删除node_modulespackage-lock.json
  • 运行:

    1
    npm install

我通过在项目中安装angularCLI修复了此问题。

1
npm install -D @angular/cli

,然后使用npx

运行命令

1
npx ng generate component home

希望对您有所帮助


您可以通过执行以下命令来解决此问题:

1
2
npm uninstall -g @angular/cli
yarn global add @angular/cli

要获取更多帮助,请点击此链接,因为这似乎是同一问题的副本。