You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a component library that I am bundling as an ESModule with Vite. I am consuming this library in a Nextjs app. The Nextjs app was setup with this example from the official MUI examples.
I am importing a component from my library into my /about page in the Nextjs app. When I start the app it loads up fine and I can go to the /about route and see my component with its styles being applied. But if I refresh the page while still on that route I get the error TypeError: Cannot read properties of null (reading 'key')
The error happens on this line of bundled code className += cache.key + "-" + serialized.name; inside of the withEmotionCache function.
I saw another issue where this was caused by multiple versions of @emotion/cache, but I have verified that isn't the case in my App. npm ls @emotion/cache as well as the other emotion dependencies shows only one version of each.
My library used to be bundled with the UMD format which worked fine, its only when switching to ESModule format that is breaking. I also tried using webpack instead of Vite and got the same error.
You were still bundling a lot of things from Emotion because this way you were only externalizing exact matches. So @emotion/react/jsx-runtime got pulled in (as it wasn't matched by external) and transitively a lot of of other things got pulled in.
Current behavior:
I have a component library that I am bundling as an ESModule with Vite. I am consuming this library in a Nextjs app. The Nextjs app was setup with this example from the official MUI examples.
I am importing a component from my library into my
/about
page in the Nextjs app. When I start the app it loads up fine and I can go to the/about
route and see my component with its styles being applied. But if I refresh the page while still on that route I get the errorTypeError: Cannot read properties of null (reading 'key')
The error happens on this line of bundled code
className += cache.key + "-" + serialized.name;
inside of thewithEmotionCache
function.I saw another issue where this was caused by multiple versions of
@emotion/cache
, but I have verified that isn't the case in my App.npm ls @emotion/cache
as well as the other emotion dependencies shows only one version of each.My library used to be bundled with the UMD format which worked fine, its only when switching to ESModule format that is breaking. I also tried using webpack instead of Vite and got the same error.
To reproduce:
yarn
to install dependenciesyarn dev
to start applocalhost:3000
and click theGo to the about page
linkExpected behavior:
No error about cache being null
Environment information:
react
version: 18.2.0@emotion/react
version: 11.10.0@emotion/cache
version: 11.10.1@emotion/server
version: 11.10.0The text was updated successfully, but these errors were encountered: