错误找不到模块'@angular/material
Posted
技术标签:
【中文标题】错误找不到模块\'@angular/material【英文标题】:Error Cannot find module '@angular/material错误找不到模块'@angular/material 【发布时间】:2018-07-11 20:29:57 【问题描述】:错误
找不到模块'@angular/material
app.module.ts
import MaterialModule from '@angular/material';
链接:https://material.angular.io/guide/getting-started
npm install --save @angular/material @angular/cdk
我尝试过的解决方案
npm 更新
它不起作用。
ng --version
@angular/cli: 1.2.1
node: 8.3.0
os: win32 x64
@angular/animation: 4.0.0-beta.8
@angular/animations: error
@angular/cdk: error
@angular/common: 4.3.2
@angular/compiler: 4.3.2
@angular/core: 4.3.2
@angular/forms: 4.3.2
@angular/http: 4.3.2
@angular/material: error
@angular/platform-browser: 4.3.2
@angular/platform-browser-dynamic: 4.3.2
@angular/router: 4.3.2
@angular/cli: 1.2.1
@angular/compiler-cli: 4.4.3
@angular/language-service: 4.3.2
在运行 npm 命令材料模块停止工作后,任何人都可以建议我。
我已经做了工作演示https://github.com/afeef1915/Angular2-Symfony3-Demo
所有代码都运行良好。
欢迎提出任何建议。安装材料时出错
D:\Angular2-Symfony3-Demo-master>npm install --save @angular/material @angular/cdk
npm WARN @angular/animation@4.0.0-beta.8 requires a peer of @angular/core@4.0.0-beta.8 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/cdk@2.0.0-beta.12 requires a peer of @angular/core@~4.4.4 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/cdk@2.0.0-beta.12 requires a peer of @angular/common@~4.4.4 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler-cli@4.4.3 requires a peer of @angular/compiler@4.4.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler-cli@4.4.3 requires a peer of @angular/core@4.4.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/material@2.0.0-beta.12 requires a peer of @angular/core@~4.4.4 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/material@2.0.0-beta.12 requires a peer of @angular/common@~4.4.4 but none is installed. You must install peer dependencies yourself.
npm ERR! path D:\Angular2-Symfony3-Demo-master\node_modules\@angular\cdk
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'D:\Angular2-Symfony3-Demo-master\node_modules\@angular\cdk' -> 'D:\Angular2-Symfony3-Demo-master\node_modules\@angular\.cdk.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\mohd\AppData\Roaming\npm-cache\_logs\2018-02-01T13_42_49_724Z-debug.log
包.json
"name": "angular2-bug-testing",
"version": "0.0.0",
"license": "MIT",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
,
"private": true,
"dependencies":
"@angular/animation": "^4.0.0-beta.8",
"@angular/animations": "^4.3.3",
"@angular/cdk": "^2.0.0-beta.12",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.3.6",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/material": "^2.0.0-beta.8",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"angular-datatables": "^4.2.0",
"angular-in-memory-web-api": "^0.3.2",
"core-js": "^2.4.1",
"datatables.net": "^1.10.15",
"datatables.net-buttons-dt": "^1.3.1",
"datatables.net-dt": "^1.10.15",
"hammerjs": "^2.0.8",
"jquery": "^3.2.1",
"json-server": "^0.12.0",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
,
"devDependencies":
"@angular/cli": "1.2.1",
"@angular/compiler-cli": "^4.4.3",
"@angular/language-service": "^4.0.0",
"@types/datatables.net": "^1.10.5",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/jquery": "^3.2.11",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
【问题讨论】:
好像没有安装材料模块。当您点击 npm install 命令时,您是否在控制台中遇到任何错误? 你可以看到 github 代码在我运行 npm cmd 后立即运行,然后出现错误 尝试通过“npm uinstall --save @angular/material”卸载并再次安装“npm install --save @angular/material” 安装材料时出现更新错误 我已经克隆了你的 repo 并成功安装了所有 npm。我正在使用 npm 5.4.2。尝试更新您的 npm 并在新位置点击 npm install。 【参考方案1】:查看错误,您会看到某些包需要 angular v.4.4.4。所以我建议你将所有 @angular-packages 更新到 v.4.4.4。
按照以下步骤操作:
1.) 移除 node_modules
2.) npm cache clean
3.) 打开 packages.json 并将所有 @angular-packages 的版本设置为 "^4.4.4"
4.) npm install
【讨论】:
我已经用 cmd 更新了>npm update -D && npm update -S【参考方案2】:这里是材料2的changelog:
它说:Angular Material 现在需要 Angular 4.4.3 或更高版本,因为 2.beta-11
如果你想要最新版本的材料,你必须升级到 Angular 5+
如果您想坚持使用 4.3.2 版本,您可以安装的最后一个版本是 2.0.0-beta10(我不建议这样做)
【讨论】:
以上是关于错误找不到模块'@angular/material的主要内容,如果未能解决你的问题,请参考以下文章
找不到模块'@angular-devkit/schematics/tasks'
Angular Material 找不到 Angular Material 核心主题
SassError:找不到要导入的样式表。 @use '~@angular/material' 作为垫子;