TypeError: Cannot read property 'key' of undefined on server side render
See original GitHub issueemotion
version:@emotion/core: 10.0.6
react
version: 16.4.2
Relevant code:
const Carousel = () => {
return <div css={{
backgroundColor: 'hotpink',
'&:hover': {
color: 'lightgreen'
}
}}>Hello</div>;
};
What you did:
Seems to be failing for server side render (see error in What happened) Works on client render.
I tried to migrate from emotion 9 to 10.
I have moved over the component code to use @emotion/core
and used the import:
/** @jsx jsx */
import { css, jsx } from '@emotion/core';
I have also removed all the server side render code associated with emotion 9 (eg: renderStylesToString
)
Maybe im missing something?
What happened:
Got this error on server side render (client render is ok):
TypeError: Cannot read property 'key' of undefined
at insertStyles (webpack-internal:///./node_modules/@emotion/utils/dist/utils.esm.js:17:25)
at render (webpack-internal:///./node_modules/@emotion/core/dist/core.esm.js:122:82)
at eval (webpack-internal:///./node_modules/@emotion/core/dist/core.esm.js:163:10)
at Object.eval [as children] (webpack-internal:///./node_modules/@emotion/core/dist/core.esm.js:83:18)
at ReactDOMServerRenderer.render (webpack-internal:///../fe-build/node_modules/react-dom/cjs/react-dom-server.node.development.js:3290:55)
at ReactDOMServerRenderer.read (webpack-internal:///../fe-build/node_modules/react-dom/cjs/react-dom-server.node.development.js:3057:29)
at renderToString (webpack-internal:///../fe-build/node_modules/react-dom/cjs/react-dom-server.node.development.js:3524:27)
at Object.eval [as serverRender] (webpack-internal:///../fe-build/lib/fe-server/demo/server.js:37:89)
at render (/Users/martin.jujou/Documents/projects/fe-build/lib/server.js:76:62)
at Layer.handle [as handle_request] (/Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/layer.js:95:5)
at /Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/index.js:281:22
at param (/Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/index.js:354:14)
at param (/Users/martin.jujou/Documents/projects/fe-build/node_modules/express/lib/router/index.js:365:14)
Reproduction:
Not sure if this is associated with our internal webpack tooling Hard to reproduce on a code sandbox link with our internal tooling
Problem description:
See above.
Suggested solution:
? Not sure
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Uncaught TypeError: Cannot read properties of undefined ...
I am trying to use React to extract a JSON data from my server and render it with two functions. But it seems...
Read more >How to Prevent the TypeError: Cannot Read Property Map of ...
A guide on the root cause of 'cannot read map of undefined' as well as techniques and tools to prevent this error.
Read more >error in render: "typeerror: cannot read properties of undefined ...
I think it has something to do with the data being rendered after the html. You can probably solve this by: Adding v-if...
Read more >Resolving the JavaScript Promise Error "TypeError: Cannot ...
TypeError - Cannot read property 'then' of undefined is thrown when the caller is expecting a Promise to be returned and instead receives ......
Read more >How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
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 also ran into this error while running mocha tests, so I needed to make emotion think I was running on a browser by adding
global.HTMLElement = window.HTMLElement;
to my jsdom setup.Same problem for me when running tests via Jasmine + JSDOM but the suggestion from @winstondispatch above solved it!