Emotion compiler not properly working when using "paths" in TypeScript since 13.5.x
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/Itrulia/material-ui-next-nx
To Reproduce
-
npm install && npx nx dev emotion-test
-
Open
http://localhost:3000 -
Inspect the HTML output and see
.mui-fh6enu{color:pink;}.mui-fh6enu .undefined{color:#f00!important;}.mui-bdz642{color:pink;} -
Change next to
~13.4.19and it works. -
OR move
${StyledPageWebsite} {
color: #f00 !important;
}
to the app (for example index.ts) and it works again.
Current vs. Expected behavior
The emotion plugin does not seem to be applied to a library that is referenced via the tsconfig paths. Component selectors by emotion thus don't work properly.
Expected (v13.4.x) vs Now (15.0.0)
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 22.8.0
npm: 10.8.2
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 15.0.1 // Latest available version is detected (15.0.1).
eslint-config-next: 14.2.3
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.4
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
SWC
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
When changing next to ~13.4.19 it works again, changing it to ~13.5.0 it stopps working.
At first I thought it was this change: https://github.com/vercel/next.js/commit/311eea4c6ab847548d81421a8edbf86ac77341f9
But this is actually setting it to @emotion/react:
console.error(isServerLayer, (jsConfig == null ? void 0 : (_jsConfig_compilerOptions4 = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions4.jsxImportSource) ?? ((compilerOptions == null ? void 0 : compilerOptions.emotion) && !isServerLayer ? "@emotion/react" : "react"))
> false @emotion/react
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked material-ui-next-nx reproduction and compare Next.js 13.4.19 with 13.5.0 using the listed npm and nx command. Inspect the SWC/Emotion compiler behavior when libraries resolve through tsconfig paths, then verify that the generated HTML no longer contains .undefined and matches the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, react, typescript
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100