TypeError: Cannot read property 'key' of null on SSR
See original GitHub issueCurrent behavior:
Using the css
property works on the client, but on SSR gives this error:
Encountered error "#<ExecJS::ProgramError: TypeError: Cannot read property 'key' of null>" when prerendering HelloWorld with {"greeting":"Hello from react-rails."}
insertStyles ((execjs):2165:25)
Related issue: https://github.com/emotion-js/emotion/issues/1185
To reproduce:
The app I’m integrating this in is a Rails app using https://github.com/reactjs/react-rails so I made a repro with it. Hopefully you have ruby installed 🤞.
git clone git@github.com:ksweetie/emotion-ssr.git
cd emotion-ssr/
bundle
yarn
rails s
// visit localhost:3000/foo/foo
Here’s a list of files I changed, otherwise it’s a stock Rails app. Changing prerender: true
to false
in foo.html.erb
should show that it’s working on the client.
app/views/foo/foo.html.erb
app/javascript/components/HelloWorld.tsx
config/webpack/loaders/typescript.js
tsconfig.json
babel.config.js
Expected behavior:
Turning on SSR doesn’t give an error.
Environment information:
react
version: 16.12.0emotion
version: 10.0.27
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (6 by maintainers)
Top Results From Across the Web
getting error "TypeError: Cannot read properties of null ...
@BraceSproul I have this error and I AM importing react . I'm using the latest nextjs, react and typescript. – Kirk Ross. Dec...
Read more >cannot read properties of null (reading 'trim') - You.com
You're getting error. Uncaught TypeError: Cannot read property 'trim' of undefined in Jquery. that means, the variable vname is undefined .
Read more >How to Avoid the Infamous "Cannot read properties of ... - Bitovi
As a JavaScript developer, I'm sure you've encountered the frustrating runtime TypeError Cannot read properties of undefined .
Read more >Cannot read property 'medium' of null" Cant figure it out! - Reddit
I keep getting a "TypeError: Cannot read property 'medium' of null" particular in my second component that contains an img key from an...
Read more >cannot read property of undefined redux - Retro Remix Advance
DesignUncaught TypeError: Cannot read properties of undefined (reading 'remove') ... Render Error: 'TypeError: Cannot read property [propertyName] of null'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was using emotion
v10.0.9
, and it was working fine. Once I went tov10.0.27
, that’s when the issue occurred.The issue is that
cache
isnull
inrender
inside of@emotion/core
. So when it callsutils.getRegisteredStyles
andutils.insertStyles
, it breaks.The codebase I’m working with is using Enzyme. If I
mount
, it breaks the test in the same way as the original poster. Allcss
props activate without a cache provider, and it’s not creating one.I believe it’s because of this:
Specifically
typeof HTMLElement !== 'undefined'
. It’s not auto-creating a cache when that happens.@lucat1 this particular problem happens because
.10
and.12
prereleases got mixed there and there were some breaking changes in between them, so older version of@emotion/css
has been crashing while using newer@emotion/cache
. I’ve prepared a PR to fix this: https://github.com/zeit/next.js/pull/11414