vue-storefront-api
vue-storefront-api copied to clipboard
Fixed export of abstract proxies
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
}
@pkarw Done
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 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 =
.
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.
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.
@ResuBaka did you reproduce the issue?
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 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.
I think we should merge it so all platform files are exported the same.
@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 Done. I could pick this issue up possibly in a few weeks.
@andrzejewsky is this PR still relevant and do we want to accept it?
@pkarw hmm would be nice to check it with current develop branch and then decide