-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
service injection can't be found in Embroider Optimized #1192
Comments
can you provide more information?
|
Thanks! I'm working on it. just forked the repo from #1072 |
That error message comes from ember-source itself and is potentially triggered when the service isn't registered in the container? Do you have an "app re-export" for the service in question? I experimented with "addon namespaced" service injections before and ran into similar issues. The service was stripped out of the build because of the So if there is no app re-export, the easiest fix would be to create it again. An other alternative could be to register the service in the container under that namespaced name, but it's more work to setup. |
I'm in an addon. where would the |
In the top level app folder of the addon. So if your service is located in |
This is the expected behavior if you're trying to use services directly out of an addon via the resolver's "@" syntax. Since that could target literally any file in any addon, supporting it means we couldn't optimize anything. The issue is specifically with This is the line that's not supported if you want to set staticAddonTrees to true: It's equivalent to reexport the service from the app tree as @Windvis suggests. If the reason you aren't reexporting is to avoid potential naming collisions, you can follow a pattern very similar to what you have now: - @service('test-hftnb-embroider-2@my-service') myService;
+ @service('test-hftnb-embroider-2-my-service') myService;
This would corresponding with the file `app/services/test-hftnb-embroider-2-my-service.js` in the addon. |
what if the addon doesn't have |
You can create one. As long as it's a normal v1 addon and doesn't customize |
We'd prefer not to create an |
some options:
|
@NullVoxPopuli your first two suggestions don't help with their particular scaling problem. The problem is that doubling the number of service modules in the build is expensive in a huge app. It doesn't matter whether they're auto generated or not. @elwayman02 the other alternative is to take direct responsibility for importing and registering the services, preferably in the files that consume them. Done by hand, that looks something like: import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
+ import MyService from 'test-hftnkb-embroider-2/services/my-service';
+ window.define('test-hftnkb-embroider-2/services/my-service', function() { return MyService });
export default class DemoComponent extends Component {
@service('test-hftnb-embroider-2@my-service') myService;
@action
clickedOnSomething() {
this.myService.empty();
}
} It would be possible to implement a staticServices flag analogous to staticComponents that would emit the above pattern automatically. To safely use such a flag, you'd need to eliminate all non-string-literal arguments to the service decorator across your app and all addons, and eliminate all runtime use of That would actually let us drop all of It's also probably possible to swap out the implementation of the service decorator to avoid the window.define, effectively polyfilling something like the explicit service injection RFC. |
In the short-term, we're going to try utilizing package metadata as a workaround for each addon to inform Embroider of its implicit-modules. |
want to provide a follow-up before we close this: |
getting an error: "Attempting to inject an unknown injection" when running tests with embroider-optimized. The classic ember build and embroider-safe are both testing sucessfully.
repo to reproduce: https://github.com/angelayanpan/test-hftnb-embroider-2
@service('test-hftnb-embroider-2@my-service') myService;
run:
yarn test:ember
The text was updated successfully, but these errors were encountered: