ember-cli / ember-ajax

Service for making AJAX requests in Ember applications
MIT License
212 stars 87 forks source link

Cannot override ajax service #428

Open Gaurav0 opened 5 years ago

Gaurav0 commented 5 years ago

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

alexlafroscia commented 5 years ago

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.

boris-petrov commented 5 years ago

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

lifeart commented 5 years ago

@boris-petrov same for me

lifeart commented 5 years ago

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

boris-petrov commented 5 years ago

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?

dfreeman commented 5 years ago

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?

lifeart commented 5 years ago

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

boris-petrov commented 5 years ago

@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.

dfreeman commented 5 years ago

@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 ☹️

boris-petrov commented 5 years ago

@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.

dfreeman commented 5 years ago

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.

boris-petrov commented 5 years ago

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 commented 5 years ago

@boris-petrov @dfreeman https://github.com/lifeart/ember-ajax-ts-bug Reproduction

image

dfreeman commented 5 years ago

@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.

lifeart commented 5 years ago

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

boris-petrov commented 5 years ago

@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?

chriskrycho commented 5 years ago

@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.