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

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

问题描述

当我尝试使用ng add命令安装角材组件时,出现package already installed错误.

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

找不到模块'@ 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(内部/模块/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)

我无权访问任何模块,因此我不认为这是因为该软件包已经安装,但是可能是我只是对原理图有误解.

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

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

解决方案

我猜您的node_modules出问题了,因为找不到@angular-devkit/schematics/tasks.我会清理它,然后重新安装以避免任何意外的问题,然后重试.

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

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

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

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.

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.

解决方案

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.

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天全站免登陆