ember-cli/ember-ajax

Cannot override ajax service

Gaurav0 opened this issue · 17 comments

After upgrading to latest ember-ajax, it is no longer possible to override the ajax service using a js (not ts) file.

Minimal Reproduction (Run ember test): https://github.com/Gaurav0/repro-ajax-ts

Hey @Gaurav0, thanks for opening this issue! I'll try to talk with the ember-cli-typescript folks and see if we can figure out what's going on here... Worst case scenario, I suppose we can remove the TypeScript support.

I'm still having the same issue even with ember-ajax version 5. Is anyone else having the same problem?

@boris-petrov same for me

Looks like it's floating bug, some of our builds broken, some working well.

Yes, it was like that for me before also. 5.0.0 doesn't seem to have changed that. @Turbo87 - can we reopen this issue?

The only time I've run into this issue with ember-ajax@5 was when there was also an older version of it as a transitive dependency somewhere in my project. For those of you still having this problem, can you confirm (either by checking your lockfile or using something like ember-cli-dependency-lint) that you only have v5 of ember-ajax in your build?

ya, found
image will try to catch it having only one dep

@dfreeman - I confirm that I have only ember-ajax 5 in my lock file and the issue appears. I am also using ember-cli-dependency-lint.

@boris-petrov do you have a reproduction you can share? I've tried everything I can think of to trigger the issue for myself and haven't ever managed it. At this point I don't think I'm going to be able to offer a diagnosis or fix until I can see the problem in action ☹️

@dfreeman - unfortunately I can't. :( I tried when we hit it and couldn't. Perhaps I'll try again at some point but the problem is that it's not consistent - it only fails sometimes. Are you sure you've tried it enough times?

Sorry I can't be of more help. Hopefully some day someone will come up with a nice reproduction. Let's leave the issue open until then if no one has something against that.

I've done things like leave ember test running in a loop overnight and still nothing, which makes me think there must be something in common in projects that have this issue that isn't the case in an out-of-the-box app. Even just a project where it sometimes happens would be helpful, because then I could look for what's different between that project and one where it never happens.

I don't know it will work by just looping ember test. Perhaps there has to be some change in a file somewhere so that the build-order is changed and then the bug to appear. Not sure about that, just shouting out ideas.

@lifeart - after you've fixed your duplicate ember-ajax does the bug appear on your side?

@lifeart that repo has exactly the same issue as the one we talked about yesterday—the .ts service file in app is nondeterministically conflicting with the .js one in the addon.

@dfreeman, right! After changing app/services/ajax.ts to app/services/ajax.js cannot reproduce issue with around 40 builds.

@dfreeman - I've obviously missed that. So having a .ts service file in an application, not in an addon, is not allowed when the names are in conflict? But a .js file works fine? Is this a bug or... I'm not sure how this can not be a bug. :) Is it an issue in ember-cli-typescript or somewhere else?

@boris-petrov it's effectively a caching problem. When addons inject .js files into the app namespace, and we're compiling .ts files to .js files in the consuming app (always in the app namespace), we can end up in a situation where Ember CLI sees that there is already a .js file there, so it ignores the one generated from .ts. Which one it picks up seems to be semi-random (at least: we haven't chased it down to see if it's strictly replicable).

We don't have any good way to work around this so far as we've been able to see.

It's also an anti-pattern for addons to do this in my opinion—but unfortunately, a very common anti-pattern.

(Sorry for the long delay in one of the Typed Ember crew responding; we've all had full summers.)

I recommend closing this issue; I'll reference it with a link from a new documentation-focused issue on the ember-cli-typescript repo, to which we'll point addon authors in the future.