Title: Improve error message for when Injectable() is missing · Issue #12467 · angular/angular · GitHub
Open Graph Title: Improve error message for when Injectable() is missing · Issue #12467 · angular/angular
X Title: Improve error message for when Injectable() is missing · Issue #12467 · angular/angular
Description: I'm submitting a ... [x] bug report Current behavior If component A has a dependency on service B, but service B does not have the Injectable() decorator defined, a vague error message is thrown: Can't resolve all parameters for SomeServ...
Open Graph Description: I'm submitting a ... [x] bug report Current behavior If component A has a dependency on service B, but service B does not have the Injectable() decorator defined, a vague error message is thrown: C...
X Description: I'm submitting a ... [x] bug report Current behavior If component A has a dependency on service B, but service B does not have the Injectable() decorator defined, a vague error message is throw...
Opengraph URL: https://github.com/angular/angular/issues/12467
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve error message for when Injectable() is missing","articleBody":"**I'm submitting a ...** \n\n```\n[x] bug report\n```\n\n**Current behavior**\nIf component A has a dependency on service B, but service B does not have the `Injectable()` decorator defined, a vague error message is thrown:\n\n```\nCan't resolve all parameters for SomeService: (?, ?)\n```\n\nThis is the exact same error message for [when dependencies can't be loaded](http://stackoverflow.com/questions/37902476/automatic-ordering-of-exports-in-index-ts-makes-app-crash/37907696). Up until now that error message was given because I use barrel files and the order of import/exports should be adjusted. Thus, I was thrown off when trying to fix this problem.\n\n**Expected behavior**\nA specific error message like:\n\n```\nSomeService was provided, but an `Injectable()` decorator was not found\n```\n\n**Minimal reproduction of the problem with instructions**\n- Create a service, but omit the `Injectable()` decorator. This service should have a dependency to at least one other service (defined correctly).\n \n ```\n import { Injectable } from '@angular/core';\n \n // oops, forgot the decorator\n export class SomeService {\n constructor(private otherService: OtherService) { }\n }\n \n @Injectable()\n export class OtherService { }\n ```\n- Provide the services with the module.\n- Create a component that gets the `SomeService` injected.\n\nI used the Plnkr of the Angular quickstart to [reproduce this problem](http://plnkr.co/edit/VfNug0dJFNPcmeeboKzi?p=preview). On the `Car` service in `app/car/car.ts`, I simply removed the decorator. The console immediately shows the error:\n\n```\nCan't resolve all parameters for Car: (?, ?)\n```\n\n// Edit:\nIn the documentation, [it is mentioned that the injector will throw a `NoAnnotationError`](https://angular.io/docs/ts/latest/api/core/index/Injectable-decorator.html), but the link to [`NoAnnotationError`](https://angular.io/docs/ts/latest/api/core/index/NoAnnotationError) results in a 404.\n\n**What is the motivation / use case for changing the behavior?**\nA more precise error message would direct me to the problem instantly and the problem could have been fixed in a matter of seconds. Because this message is the exact same as when dependencies can't be resolved due to import/export order with barrel files, it now took me 30 minutes of stripping dependencies and order checking before I noticed this simple and tiny mistake.\n\n**Please tell us about your environment:**\nWindows 10, Chrome 53 and SystemJS as the module loader.\n- **Angular version:** 2.0.0 and upwards. It is still a problem in 2.1.0.\n- **Browser:** The web application crashes in all browsers. Chrome 53 and Edge 38 clearly show the error in the console. Firefox however, shows a `CompileMetadataResolver` and I'm not able to find a more specific error message.\n- **Language:** TypeScript 2.0.3.\n- **Node (for AoT issues):** 6.0.0.\n","author":{"url":"https://github.com/JPtenBerge","@type":"Person","name":"JPtenBerge"},"datePublished":"2016-10-23T09:39:58Z","url":"https://github.com/angular/angular/issues/12467"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1e952161-4419-e7ff-2d41-72bf028d118f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB08:26ECEB:1BC1923:235703A:6B0140A5 |
| html-safe-nonce | 25e8471deb3bf2d980cbd53f37c99f29d91c579292e454d4e497bcfd4c300a54 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjA4OjI2RUNFQjoxQkMxOTIzOjIzNTcwM0E6NkIwMTQwQTUiLCJ2aXNpdG9yX2lkIjoiMzI0MTY5MDk1MDAxMTAxMTIzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 942854f7911535efbacfa654fd3d34ce885d01ca8bb2ab68ff837b2cc514bab1 |
| hovercard-subject-tag | issue:184680439 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/12467/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3dad86f9a651d0a263df646dd3531063739e6875fad6ab9bfc12239b03b40666/angular/angular/issues/12467 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3dad86f9a651d0a263df646dd3531063739e6875fad6ab9bfc12239b03b40666/angular/angular/issues/12467 |
| og:image:alt | I'm submitting a ... [x] bug report Current behavior If component A has a dependency on service B, but service B does not have the Injectable() decorator defined, a vague error message is thrown: C... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JPtenBerge |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width