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.

Next.js 13 Error during SSR Rendering ReferenceError: defaultStyleFunctionMapping is not defined

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Steps:

  1. Set up a starter Next.13 app and install MUI.
  2. Disable the app folder, just use the good ol’ regular pages folder.
  3. Add a component, such as Card on a page, like index.
  4. Run the dev server using next dev --turbo
  5. Error.

Current behavior 😯

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - initial compilation 20ms
error - [rendering] [root of the dev server]/
  Error during SSR Rendering
  ReferenceError: defaultStyleFunctionMapping is not defined
    at unstable_createStyleFunctionSx (.next/server/pages/chunks/node_modules__292df6.pnpm.js:16:70)
    at <unknown> (.next/server/pages/chunks/node_modules__292df6.pnpm.js:104:24)
    at Module.[project-with-next]/node_modules/.pnpm/@mui+system@5.10.10_dovxhg2tvkkxkdnqyoum6wzcxm/node_modules/@mui/system/esm/styleFunctionSx/styleFunctionSx.js (ecmascript) (.next/server/pages/chunks/node_modules__292df6.pnpm.js:1558:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/node_modules__292df6.pnpm.js:1:0)
    at Module.[project-with-next]/node_modules/.pnpm/@mui+system@5.10.10_dovxhg2tvkkxkdnqyoum6wzcxm/node_modules/@mui/system/esm/styleFunctionSx/index.js (ecmascript) (.next/server/pages/chunks/node_modules__292df6.pnpm.js:1419:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/node_modules__292df6.pnpm.js:1:0)
    at Module.[project-with-next]/node_modules/.pnpm/@mui+system@5.10.10_dovxhg2tvkkxkdnqyoum6wzcxm/node_modules/@mui/system/esm/index.js (ecmascript) (.next/server/pages/chunks/node_modules__292df6.pnpm.js:1976:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:1:0)
    at Module.[project-with-next]/node_modules/.pnpm/@mui+material@5.10.11_5rzy53przelm5jchjmb5vr6dxy/node_modules/@mui/material/esm/styles/adaptV4Theme.js (ecmascript) (.next/server/pages/chunks/_9d4207.js:3897:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:1:0)
    at Module.[project-with-next]/node_modules/.pnpm/@mui+material@5.10.11_5rzy53przelm5jchjmb5vr6dxy/node_modules/@mui/material/esm/styles/index.js (ecmascript) (.next/server/pages/chunks/_9d4207.js:1276:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:2:0)
    at Module.[project-with-next]/node_modules/.pnpm/@mui+material@5.10.11_5rzy53przelm5jchjmb5vr6dxy/node_modules/@mui/material/esm/index.js (ecmascript) (.next/server/pages/chunks/_9d4207.js:1128:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:1:0)
    at Module.[project-with-next]/pages/index.js (ecmascript) (.next/server/pages/chunks/_9d4207.js:264:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at getOrInstantiateModuleFromParent (.next/server/pages/chunks/_9d4207.js:40786:12)
    at esmImport (.next/server/pages/chunks/_9d4207.js:40515:20)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:1:0)
    at Object.[project-with-next]/pages/index.js/server-renderer.tsx (ecmascript) (.next/server/pages/chunks/_9d4207.js:230:3)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40706:21)
    at runModuleExecutionHooks (.next/server/pages/chunks/_9d4207.js:40744:5)
    at instantiateModule (.next/server/pages/chunks/_9d4207.js:40705:5)
    at instantiateRuntimeModule (.next/server/pages/chunks/_9d4207.js:41290:12)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:40345:1)
    at <unknown> (.next/server/pages/chunks/_9d4207.js:41341:39)
    at <anonymous>
    at Object.registerChunk [as push] (.next/server/pages/chunks/_9d4207.js:41341:25)
    at Object.<anonymous> (.next/server/pages/chunks/[embedded_modules]_@vercel_turbopack-next_40e91d.js:1:41)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (.next/server/pages/index.js:11:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at <unknown> (node:internal/main/run_main_module:22:47)

Expected behavior 🤔

No error.

Context 🔦

Using Next 13 + MUI + Emotion + next dev --turbo.

More details here: https://github.com/vercel/turbo/discussions/2312#discussioncomment-3966587

Works without --turbo.

Your environment 🌎

{
	"name": "example",
	"version": "0.1.0",
	"private": true,
	"scripts": {
		"dev": "next dev",
		"build": "next build",
		"start": "next start",
		"lint": "next lint"
	},
	"dependencies": {
		"@emotion/react": "^11.10.5",
		"@emotion/styled": "^11.10.5",
		"@mui/material": "^5.10.11",
		"next": "13.0.0",
		"react": "18.2.0",
		"react-dom": "18.2.0"
	},
	"devDependencies": {
		"eslint": "8.26.0",
		"eslint-config-next": "13.0.0",
		"prettier": "^2.7.1",
		"typescript": "^4.8.4"
	}
}

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RPDeshaiescommented, Nov 2, 2022

Also, as a side note, AFAIK NextJS uses Turbopack / SWC, and not ESbuild.

0reactions
mnajdovacommented, Nov 10, 2022

@mnajdova I think you should take the label off of this for “not our responsibility” right?

I’ve left a comment on the pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js dynamic import with server-side-rendering turned off ...
This works fine in development, but when I try to build the project (next build), it throws a "window is not defined" error...
Read more >
react-hydration-error - Next.js
When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the...
Read more >
How to solve Next.js window is not defined
Solve a the common ReferenceError: next.js window is not defined error that you may see when doing SSR & pre-rendering.
Read more >
Solve “document is not defined” errors in Next.js | by WebTutPro
You can import your Scroll component using dynamic imports and the srr: false option. This way your component won't even be rendered on...
Read more >
How to Fix "window is not defined" in Next.js - Upmostly
This issue has to do with Server-Side Rendering in Next.js. Next.js will by default try to use SSR for your site.
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