Cannot find module @angular/material
I'm trying to add Angular Material to my application but it first required me to upgrade to Angular5 which was fine. But now it's not working as it couldn't find the Material module although I've installed it following the getting started tutorial with:
npm install --save @angular/material @angular/cdk
The error I'm getting is literally:
`ERROR in src/app/app.module.ts(6,52): error TS2307: Cannot find module '@angular/material'.`
Which correspond to this import instruction:
import { MatButtonModule, MatCheckboxModule } from '@angular/material';
Is this caused because Angular Material is still an RC version?
Thanks.
Works fine to me. Have you tried to restart angluar cli? Or remove node_modules/ then run npm install again :)
@isra-fel Thanks for your response. I actually deleted the whole project and re-generated it with the newly-installed @angular/cli 1.5 (before that I've removed the whole directory ~/.node_modules where the previous version of @angular/cli was installed, as I set npm config set prefix ~/.node_modules).
Can I know which versions of Material, Animations, and CDK you've installed? For me when I installed them I always get a warning that the version required isn't installed (some require @angular/core 5.0.1 other the 5.0.0 version).
@h4k1m0u my material & cdk are 5.0.0-rc0, animations is 5.0.0
Did you actually import for your parent angular module?
@NgModule({
imports: [
MatButtonModule,
MatCheckboxModule
]
})
@merlosy Yes I already have those imports in my app.module.ts and in the right place.
@isra-fel I'm not 100% sure the error is caused by a mismatch in the versions of the different librairies, but I've noticed that @angular/material doesn't appear when I do ng --version at the root of my project. Here is its output:
Angular CLI: 1.5.0
Node: 8.7.0
OS: linux x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.2
typescript: 2.4.2
webpack: 3.8.1
Another thing to mention is that when I install material with npm install -g @angular/material, I get the following output (that's why I'm wondering whether material-5.0.0 doesn't have some issues with angular-5.0.1):
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/common@^5.0.0 but none is installed. You must install peer dependencies yourself.
+ @angular/[email protected]
updated 1 package in 2.957s
@h4k1m0u Can you try installing material locally instead of -g?
Thanks very much @isra-fel, without the -g parameter it managed to install @angular/material: 5.0.0-rc0 while angular and the rest of the librairies are v5.0.1:
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.5.0
@angular/material: 5.0.0-rc0
However, now it's complaining about the @angular/cdk being not installed (I guess because @angular/cdk was installed with the -g parameter as well).
What fixed all of this is to install them according to the official website, by removing the -g switch from both:
npm install --save @angular/material @angular/cdk
Why would you install these as global dependencies? Your package.json should imho be enough to recreate your project deps, bar node of course.
That also means typescript, webpack etc should be installed locally.
restart vscode
install the npm install --save @angular/material @angular/cdk in your project directory, as well as the ng add angular/material
it should have to work
I am using ubuntu 16.04 LTS. I faced same problem while getting started with angular material I followed all the steps from Angular Material
Then once again suing sudo su I used npm install --save @angular/material @angular/cdk.
It worked..
ISSUE :
Angular Materials is not showing in browser , here below i describe my angular version ,
Notes: no error messasge is display in console
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _ | | | | |/ _ | '| | | | | | |
/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
Angular CLI: 7.2.0 Node: 10.16.1 OS: win32 ia32 Angular: 7.2.0 ... animations, cli, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.7.0 @angular-devkit/build-angular 0.7.0 @angular-devkit/build-optimizer 0.7.0 @angular-devkit/build-webpack 0.7.0 @angular-devkit/core 0.7.0 @angular-devkit/schematics 7.2.0 @angular/cdk 5.2.5 @angular/material 5.2.5 @ngtools/webpack 6.1.0 @schematics/angular 7.2.0 @schematics/update 0.12.0 rxjs 6.2.2 typescript 3.2.2 webpack 4.9.2
package.json
"dependencies": { "@angular/animations": "4.1.2", "@angular/cdk": "^5.2.5", "@angular/common": "7.2.0", "@angular/compiler": "7.2.0", "@angular/core": "7.2.0", "@angular/forms": "7.2.0", "@angular/http": "7.2.0", "@angular/material": "^5.2.5", "@angular/platform-browser": "7.2.0", "@angular/platform-browser-dynamic": "7.2.0", "@angular/router": "7.2.0", "@ng-bootstrap/ng-bootstrap": "4.1.0", "angular-file-uploader": "^5.0.2", "bootstrap": "4.1.2", "core-js": "2.4.1", "jquery": "3.2.1", "jw-bootstrap-switch-ng2": "2.0.1", "ng2-file-upload": "^1.3.0", "ng2-nouislider": "1.7.12", "nouislider": "9.2.0", "popper.js": "1.14.4", "rxjs": "6.2.2", "rxjs-compat": "6.2.2", "zone.js": "0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "0.7.0", "@angular/cli": "7.2.0", "@angular/compiler-cli": "7.2.0", "@angular/language-service": "7.2.0", "@types/jasmine": "2.5.45", "@types/node": "6.0.60", "codelyzer": "4.4.3", "jasmine-core": "2.6.2", "jasmine-spec-reporter": "4.1.0", "karma": "3.0.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.4.0", "ts-node": "3.0.4", "tslint": "5.3.2", "typescript": "3.2.2" } }
Closed Add stylesheet in your index.html file
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.