Error: Cannot find module '@angular-devkit/schematics' and Cannot find module '@angular-devkit/schematics'

醉酒当歌 提交于 2020-02-28 04:21:19

问题


When I try to generate angular material data-table, I am getting below error. Please guide me to resolve this error.

ng command used for generate the data-table:

ng g @angular/material:material-table --name=data-table

after executing above ng command I am getting below error in my terminal

Cannot find module '@angular-devkit/schematics'

Error: Cannot find module '@angular-devkit/schematics'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\Users\Lenovo\my-wks\meanStackDemo\node_modules\@angular\material\schematics\ng-generate\table\index.js:10:22)

Please share your suggestion or guidance to resolve this. Thanks .

Happy Holidays!:-)


回答1:


Finally I got blow conclusion from this error.

1 make sure below command is executed in right directory or not.

'npm install --save @angular/material @angular/cdk @angular/animations hammerjs'

for my case 'C:\Users\Lenovo\my-wks\meanStackDemo\contacts>' -- correct path

'C:\Users\Lenovo\my-wks\meanStackDemo>'--previous wrong path

now i can generate the data-table component by using below command 'ng g @angular/material:material-table --name=data-table'

Thanks rvkant! your explanation is very useful to understand the issue.Thanks once again.




回答2:


When I tried installing angular material to my project I got the same error like

Cannot find module '@angular-devkit/schematics/tasks' in angular 7

So I did

npm i @angular-devkit/schematics
npm i @angular-devkit/core

it resolves the problem.




回答3:


As per material design documentation

Blockquote Schematics are included with both @angular/cdk and @angular/material. Once you install the npm packages, they will be available through the Angular CLI.

Using the command below will install Angular Material, the Component Dev Kit (CDK), and Angular Animations in your project. Then it will run the install schematic.

ng add @angular/material

And then generate data-table component by using the following command

ng generate @angular/material:table <component-name>



来源:https://stackoverflow.com/questions/53940350/error-cannot-find-module-angular-devkit-schematics-and-cannot-find-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!