embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
339 stars 140 forks source link

importSync seems to have an issue with double "default" wrapping in Fastboot environments #1203

Open mansona opened 2 years ago

mansona commented 2 years ago

Hey folks 👋

I'm tracking down why one of my Empress projects wasn't working in the intended Fastboot (prember) build, I tracked it down to the change that I recently made to ember-get-config that now makes use of importSync under the hood.

The problem is a simple one, but a bit too complex for me to even know where to start looking for a root cause or solution. Essentially I'm using importSync to get the parent app's config module and for some reason in a Fastboot environment it requires me to go config.default.default to actually get to the config that is exported.

I have a workaround that will work for now in ember-get-config https://github.com/mansona/ember-get-config/pull/44 but I would prefer that I don't keep this hack in there because I assume I'm not the only one that will be experiencing this issue.

Any guidance on debugging this issue would be super appreciated 👍

mansona commented 2 years ago

So turns out I was able to find the part of the code that is relevant (tis a bit hard since it's all implemented in a babel transform, but also doesn't have a dedicated file like the other macros)

https://github.com/embroider-build/embroider/blob/631eb5d1b273ac3dde54902fe9c074493f36bc1a/packages/macros/src/babel/macros-babel-plugin.ts#L133-L142

Essentially I'm wondering if we want to do some sort of detection that we're in Node at this spot and make it "unwrap" the second default at this point 🤔

At this point I don't even know what the expected behaviour is supposed to be and what point in the process is going wrong. I've just discovered the fastboot fixtures and I'm going to see if I can recreate using importSync in there and see if I can confirm if it's a fastboot issue or not 👍