Replies: 1 comment 3 replies
-
I ran into a similar issue and managed to fix it by adding the following to the library's Vite config
Docs: https://rollupjs.org/configuration-options/#output-interop |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a component library with Vite + TS and use library mode to export that to commonjs & es. Within the library and within vite, everything works as expected. When using this library in a consuming project, we have had a couple problems around dependencies that use default exports. In vite, something like:
Will correctly have
styled
pointed at the dependency'sdefault
export. But in our consuming library, we get an error withq is not a function
whereq=require('@emotion/styled')
. With debugging, I can see that this is becauseq
is now pointed directly at the whole module, but it should be pointed at thedefault
.I have yet to land on the correct solution for either the library end or the consuming project to fix it. We have a hack in place for one such issue we encountered where we essentially check the import on the library side:
const emotion = typeof styled === 'function' ? styled : styled.default
. But that seems very hacky to put into place everywhere. The consuming projects do usually need a change to usemoduleResolution: nodeNext
(ornode16
) so I don't know if that is also related.Anyone have an idea of how our publish library could work better in the consuming projects?
Library side
tsconfig.json
:Library side
tsconfig.node.json
:Library's vite config:
Beta Was this translation helpful? Give feedback.
All reactions