'ng add @angular/material' 产生错误,为什么? [英] 'ng add @angular/material' produces error, why?

查看:26
本文介绍了'ng add @angular/material' 产生错误,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 ng add 命令安装角材料组件时,我收到一个 package already installed 错误.

When I try to install angular material components by using the ng add command I get an package already installed error.

$ ng 添加@angular/material
跳过安装:软件包已安装

$ ng add @angular/material
Skipping installation: Package already installed

找不到模块'@angular-devkit/schematics/tasks'
错误:找不到模块@angular-devkit/schematics/tasks"
在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
在 Function.Module._load (internal/modules/cjs/loader.js:506:25)
在 Module.require (internal/modules/cjs/loader.js:636:17)
在要求 (internal/modules/cjs/helpers.js:20:18)
在对象.(C:\Users\emilbonnek\node_modules@angular\material\schematics\ng-add\index.js:10:17)
在 Module._compile (internal/modules/cjs/loader.js:688:30)
在 Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
在 Module.load (internal/modules/cjs/loader.js:598:32)
在 tryModuleLoad (internal/modules/cjs/loader.js:537:12)
在 Function.Module._load (internal/modules/cjs/loader.js:529:3)
在 Module.require (internal/modules/cjs/loader.js:636:17)
在要求 (internal/modules/cjs/helpers.js:20:18)
在新的 ExportStringRef(C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\tools\export-ref.js:18:25)
在 NodeModulesEngineHost._resolveReferenceString(C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\tools\node-module-engine-host.js:94:21)
在 NodeModulesEngineHost.createSchematicDescription(C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\tools\file-system-engine-host-base.js:179:34)
在 SchematicEngine.createSchematic (C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\src\engine\engine.js:219:38)

Cannot find module '@angular-devkit/schematics/tasks'
Error: Cannot find module '@angular-devkit/schematics/tasks'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (C:\Users\emilbonnek\node_modules@angular\material\schematics\ng-add\index.js:10:17)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at new ExportStringRef(C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\tools\export-ref.js:18:25)
at NodeModulesEngineHost._resolveReferenceString (C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\tools\node-module-engine-host.js:94:21)
at NodeModulesEngineHost.createSchematicDescription(C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\tools\file-system-engine-host-base.js:179:34)
at SchematicEngine.createSchematic (C:\Users\emilbonnek\Documents\private\ultimating\node_modules@angular-devkit\schematics\src\engine\engine.js:219:38)

我无权访问任何模块,所以我不认为这是因为该包已经安装,但也可能是我对原理图有一些误解.

I don't have access to any of the modules, so I don't think its because the package is already installed, however it could be that I have simply misunderstood something about schematics.

我使用的是 Angular CLI 版本 8.0.3,对于 devkit/core 和 devkit/schematics 也是如此.我完全确定我在正确的目录中运行命令.

I am on angular CLI version 8.0.3 and same for devkit/core and devkit/schematics. I am completely sure I am running the command in the right directory.

为什么命令没有按预期执行?任何帮助表示赞赏.

Why is the command not doing as it is supposed to? any help is appreciated.

推荐答案

我猜你的 node_modules 有问题,因为它没有找到 @angular-devkit/schematics/tasks.我会清理它并重新安装以避免任何意外问题,然后再试一次.

I guess there's something wrong with your node_modules, as it doesn't find @angular-devkit/schematics/tasks. I'd clean it and reinstall again to avoid any unexpected problems, and try again.

采用原理图范式意味着我们不再直接编辑package.json,只使用ng addng update,但正如 Aj1 所说,有时它可以安装包并在此之后运行原理图.

Adopting the schematics paradigm means that we do not edit the package.json directly anymore, and use ng add and ng update only, but as Aj1 said, sometimes it works installing the package and running the schematic after that.

这篇关于'ng add @angular/material' 产生错误,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆