Skip to content

Generated service cannot be injected until Ember serve is restarted  #16133

@myartsev

Description

@myartsev

I got stuck for a little while trying to figure out why I couldn't inject a newly created service. Turns out that restarting ember serve solved the issue, but still, here are the reduced steps to reproduce the problem every time:

ember new super-rentals
ember s

In another terminal:
ember g service shopping-cart
ember g component foo-cmp

application.hbs
{{foo-cmp}}

foo-cmp.js

import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
  shoppingCart: service()
});

The full error message in the browser console:

"Error: Assertion Failed: Attempting to inject an unknown injection: 'service:shoppingCart'
at new EmberError (http://localhost:4200/assets/vendor.js:24147:25)
at assert (http://localhost:4200/assets/vendor.js:24390:15)
at Registry.validateInjections (http://localhost:4200/assets/vendor.js:21434:66)
at FactoryManager.create (http://localhost:4200/assets/vendor.js:21019:35)
at Proxy.create (http://localhost:4200/assets/vendor.js:20802:20)
at CurlyComponentManager.create (http://localhost:4200/assets/vendor.js:25615:37)
at http://localhost:4200/assets/vendor.js:13213:33
at AppendOpcodes.evaluate (http://localhost:4200/assets/vendor.js:11612:13)
at VM.next (http://localhost:4200/assets/vendor.js:18788:32)
at TemplateIterator.next (http://localhost:4200/assets/vendor.js:18859:28)"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions