vue-storefront-api icon indicating copy to clipboard operation
vue-storefront-api copied to clipboard

Fixed export of abstract proxies

Open mbarouski opened this issue 5 years ago • 13 comments

I got an error in src/platform/factory.ts for abstract proxies:

TypeError: adapter_class is not a constructor

It's because of the way abstract proxy is exported. Sometimes it is module.exports = and sometimes it is export default. For the 2nd variant require function gives us an object with the default field, so we have not a correct constructor:

{
  default: CorrectProxyConstructor
}

mbarouski avatar Oct 10 '19 09:10 mbarouski

@pkarw Done

mbarouski avatar Oct 11 '19 06:10 mbarouski

I don't fully understand why you are using require in the first place @maximka777. Babel is here to help so you can use modern javascript everywhere in the project. I would say it should be fixed the other way around (export default everywhere instead of module.exports)

lukeromanowicz avatar Oct 12 '19 03:10 lukeromanowicz

@lukeromanowicz I just started the project with yarn dev and have such errors. Can't say if we have babel there. And require is in the existing code https://github.com/DivanteLtd/vue-storefront-api/blob/master/src/platform/factory.ts#L17. Proxy is loaded in runtime so you use require, import expression can't be used inside function. Also I think all proxies for magento 1 and 2 use module.exports = .

mbarouski avatar Oct 12 '19 07:10 mbarouski

What I can say is that we don't have babel anymore as every thing is compiled by the typescript compiler.

Then I can't understand that you have this error as we have the same code in our project and this is just working fine on our Staging Server and locally too.

Can you give maybe some info what you are using locally.

  • Are you using the Docker way or are you running all Services locally?
  • Which Version of node are you using?

Maybe with that I can try to reproduce it locally for me.

ResuBaka avatar Oct 12 '19 08:10 ResuBaka

NodeJS v10.16.0 (can't say exact value, not near my PC). I started Elastic, Kibana, Redis via Docker, but application via yarn dev. I changed platform parameter in configuration to abstract. I suppose your staging works with Magento proxies, so you don't have this error.

mbarouski avatar Oct 12 '19 12:10 mbarouski

@ResuBaka did you reproduce the issue?

mbarouski avatar Oct 17 '19 18:10 mbarouski

any update on that @maximka777 @ResuBaka, is it still occurs? For me this fix looks weird, vsf-api works fine... we have babel / TS to provide modern JS so you shouldn't have that error

andrzejewsky avatar Nov 11 '19 20:11 andrzejewsky

@andrzejewsky IDK how you run this project, but I have the described above issue. Repeat: when you require(..) something that is exported as export default ... you get object { default: NEEDED_VALUE }. Regarding TS: there is a mix of TS and JS. Regarding Babel: not sure if it works (for me at least) and it was already discussed above https://github.com/DivanteLtd/vue-storefront-api/pull/346#issuecomment-541299273. If you don't like the fix just close this PR.

mbarouski avatar Nov 12 '19 07:11 mbarouski

I think we should merge it so all platform files are exported the same.

ResuBaka avatar Nov 12 '19 13:11 ResuBaka

@maximka777 I've realised where is the problem so basically I can accept that PR.

However, would be perfect to replace module.exports by export default and also https://github.com/DivanteLtd/vue-storefront-api/blob/master/src/platform/factory.ts#L17 to require().default - this is what just came to my mind, that's should solve your problem as well, but it needs more tests to make sure if it doesn't break anything.

So for now I'm accepting this one, but I'll create issue for to do some refactoring of exports across the whole project.

Last thing, could you please change base to release/v1.11-rc1? I'll add this to the upcoming release. Thanks

andrzejewsky avatar Nov 13 '19 13:11 andrzejewsky

@andrzejewsky Done. I could pick this issue up possibly in a few weeks.

mbarouski avatar Nov 13 '19 14:11 mbarouski

@andrzejewsky is this PR still relevant and do we want to accept it?

pkarw avatar Feb 28 '20 07:02 pkarw

@pkarw hmm would be nice to check it with current develop branch and then decide

andrzejewsky avatar Feb 28 '20 07:02 andrzejewsky