angular: Unhandled Promise rejection: TypeError: Cannot read property 'type' of null
I’m submitting a … (check one with “x”)
[X] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Met below error while running angular2 application after migrating from rc4 to rc5. app.module.ts is almost same as examples… I can’t get any hint to resolve this problem.
` zone.js:461 Unhandled Promise rejection: TypeError: Cannot read property ‘type’ of null at eval (http://localhost:4200/vendor/@angular/compiler/src/metadata_resolver.js:698:41) at Array.forEach (native) at getTransitiveModules (http://localhost:4200/vendor/@angular/compiler/src/metadata_resolver.js:697:13) at CompileMetadataResolver._getTransitiveNgModuleMetadata (http://localhost:4200/vendor/@angular/compiler/src/metadata_resolver.js:411:33) at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor/@angular/compiler/src/metadata_resolver.js:283:43) at RuntimeCompiler._compileComponents (http://localhost:4200/vendor/@angular/compiler/src/runtime_compiler.js:150:47) at RuntimeCompiler.compileModuleAndComponents (http://localhost:4200/vendor/@angular/compiler/src/runtime_compiler.js:72:37) at RuntimeCompiler.compileModuleAsync (http://localhost:4200/vendor/@angular/compiler/src/runtime_compiler.js:49:21) at PlatformRef.bootstrapModuleWithZone (http://localhost:4200/vendor/@angular/core/src/application_ref.js:368:25) at PlatformRef.bootstrapModule (http://localhost:4200/vendor/@angular/core/src/application_ref.js:361:21) Evaluating http://localhost:4200/main.js Error loading http://localhost:4200/main.js ; Zone: <root> ; Task: Promise.then ; Value: Error: TypeError: Cannot read property ‘type’ of null(…)consoleError @ zone.js:461_loop_1 @ zone.js:490drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426 zone.js:463 Error: Uncaught (in promise): Error: TypeError: Cannot read property ‘type’ of null(…)
`
in package.json:
... "dependencies": { "@angular/common": "^2.0.0-rc.5", "@angular/compiler": "^2.0.0-rc.5", "@angular/core": "^2.0.0-rc.5", "@angular/forms": "^0.3.0", "@angular/http": "2.0.0-rc.5", "@angular/platform-browser": "^2.0.0-rc.5", "@angular/platform-browser-dynamic": "^2.0.0-rc.5", "@angular/router": "^3.0.0-beta.2", "@angular2-material/button": "^2.0.0-alpha.7-2", "@angular2-material/card": "^2.0.0-alpha.7-2", "@angular2-material/checkbox": "^2.0.0-alpha.7-2", "@angular2-material/core": "^2.0.0-alpha.7-2", "@angular2-material/grid-list": "^2.0.0-alpha.7-2", "@angular2-material/icon": "^2.0.0-alpha.7-2", "@angular2-material/input": "^2.0.0-alpha.7-2", "@angular2-material/list": "^2.0.0-alpha.7-2", "@angular2-material/menu": "^2.0.0-alpha.7-2", "@angular2-material/progress-bar": "^2.0.0-alpha.7-2", "@angular2-material/progress-circle": "^2.0.0-alpha.7-2", "@angular2-material/radio": "^2.0.0-alpha.7-2", "@angular2-material/sidenav": "^2.0.0-alpha.7-2", "@angular2-material/tabs": "^2.0.0-alpha.7-2", "@angular2-material/toolbar": "^2.0.0-alpha.7-2", "angular2-grid": "^0.8.3", ... "es6-shim": "0.35.0", "gulp-ng-build": "0.0.3", "jsonwebtoken": "7.0.0", ... ... "reflect-metadata": "^0.1.3", "rxjs": "^5.0.0-beta.6", "systemjs": "0.19.26", "zone.js": "^0.6.12" ...
Expected/desired behavior
Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).
What is the expected behavior?
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
- Angular version: 2.0.0-rc.5
- Browser: [all]
- Language: [TypeScript 1.8]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 20 (2 by maintainers)
There should be a more explicit error message regardless. This one’s extremely difficult to debug.
I’m getting the same issue. Can’t figure out still as the error doesn’t show any detailed message or information about missing module / component.
For me that happens in the http request, I have a custom RequestOptions and I set Content-Type: application/json header
I remove the contet-type as angular already set that in RC.5 and it works
I’ve just had the same problem. In my case I listed my services in
imports
(wrong) instead ofproviders
in the module declaration (FooBar.module.ts
)!It seems my problem was different - yet similar error. @inska was right, it was a problem in the app.modules.ts.
I tried import @angular/http/Http when I should have been importing @angular/http/HttpModule…Urrrghh… wasted almost half a day…oh well, good lesson learned.
I figured it out by removing all dependencies, imports and services providers. Then it worked.
I added them one by one each of them and found one of my shared module created this issue.
Looks like my problem was I imported a service in both sections, providers and imports, that created this error for me.
Thank you @paistipokka ! I was trying to import ngStyle and ngClass but it turned out after your suggestion that I need to import the CommonModule. That solved the error.
Same issue here - project is too complicated to easily distill into a plunkr.
The gist of the issue was a component declared in app.module.ts and then imported into a feature module. I moved that component into a shared module which exports its instead and then imported the shared module into the feature module. This fixed the issue.
Please provide a minimal reproduce in a plunker - otherwise it is not actionable, really…