question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@emotion/cache browser specific module breaks SSR

See original GitHub issue
  • emotion version: 10.0.7
  • react version: 16.8.0

Relevant code: https://github.com/emotion-js/emotion/blob/master/packages/cache/src/index.js#L69

What you did: Tried to SSR using static-site-generator-webpack-plugin.

What happened:

ERROR in ReferenceError: document is not defined at createCache
(webpack:////node_modules/@emotion/cache/dist/cache.browser.esm.js?:109:38)

Problem description: When @emotion/cache gets imported by webpack with target: web it fails due to the browser specific module not including the check for typeof document !== 'undefined'. As mentioned in https://github.com/emotion-js/emotion/issues/1113 this is a known issue and setting target: node is not an adequate solution.

Suggested solution: Drop the browser specific version of the module.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

11reactions
johotcommented, Mar 19, 2020

Thank you for this thread!

This was actually a big problem for us! We wanted to use Emotion 10 together with ReactJS.NET for using React components inside Razor pages in ASP.NET. The problem here is we can’t use target “node” because the V8 engine it is running can’t understand it (no support for require etc). So we need to use target: "web" but still enable SSR.

By manually deleting all the browser: settings from each emotion package.json like @rdadoune suggested we got it working!

So there are definately cases where a check should be made even if it is the browser specific module.

Follow up findings:

I could also make it work without the monkey patch by setting (in webpack.config.js):

 resolve: {
      aliasFields: ["module"]
},
4reactions
Andaristcommented, Feb 27, 2019

As mentioned in #1113 this is a known issue and setting target: node is not an adequate solution.

Isnt it? Could you prepare a simple repository reproducing the issue with your setup? I could take a look then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering - Emotion
To use emotion's SSR with Next.js you need a custom Document component in pages/_document.js that renders the styles and inserts them into the...
Read more >
Server-side rendering broken after upgrading to MUI 5 (with ...
I launched the official SSR Next.js implementation. It showed it doesn't work either. Server-side rendering with JavaScript disabled. For more ...
Read more >
vite-ssr - npm
Simple yet powerful Server Side Rendering for Vite 2 in Node.js (Vue & React). ... Vite SSR can be deployed to any Node.js...
Read more >
Advanced Features: Next.js Compiler
js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for individual...
Read more >
build/index.js.map · master · plugins / CiviCRM Gutenberg ...
node_modules/@emotion/cache/dist/cache.browser.esm.js","webpack:///. ... Return the exports of the module\n \t\treturn module.exports;\n ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found