vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

If I use modules with commonjs, generates strange imports

Open DileSoft opened this issue 2 years ago • 3 comments

Hello. If in my remote project used node modules with commonjs, it generates expose js with imports like

const {default:React$1,c:commonjsGlobal,r:react,g:getDefaultExportFromCjs} = await importShared('react')

In my host project, react don't exports variables like r:react and g:getDefaultExportFromCjs. So, my remote module became incompatible with my host module. What I can do?

DileSoft avatar Jun 10 '22 11:06 DileSoft

I think this is because the product of building cjs with different build tools is inconsistent, and it's hard to get cjs to form a completely consistent output with some configuration, so I recommend using ESM in preference

ruleeeer avatar Jun 11 '22 06:06 ruleeeer

Or try to give me a reproduction of the repository, it is also possible that the bug is causing the problem

ruleeeer avatar Jun 11 '22 06:06 ruleeeer

I use react components from npm, and vite detects them as cjs. As I understand, many react components from npm is commonjs.

https://github.com/ioBroker/ioBroker.vis-widget-thermostat

DileSoft avatar Jun 11 '22 07:06 DileSoft