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 12.2.0 - Using Emtion with SWC still does not work fully

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.14.0
      npm: 8.3.1
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.2.1-canary.2
      eslint-config-next: 12.2.0
      react: 18.1.0
      react-dom: 18.1.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I use emotion in our project, before Next 12.2 emotion support in SWC was still experimental and therefore we held off and was still using babel. However, now that it’s not experimental we decided to try it out.

However, we get a build error: Error: Component selectors can only be used in conjunction with @emotion/babel-plugin, the swc Emotion plugin, or another Emotion-aware compiler transform.

Expected Behavior

I expected the swc_emotion crate in SWC to work correctly

Link to reproduction

https://codesandbox.io/s/swc-emotion-problem-gnp94o

To Reproduce

All you need is emotion/react, emotion/styled and to turn it on in next config.

Then you need two styled components, one which is a parent, and the other which will be a child. Then use Component selector ${ComponentName} to style said child.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vip30commented, Jul 26, 2022

I’m facing the exactly same issue with passing option to styled function and use that component for the selector

i.e.

styled(Abc, {  shouldForwardProp: (propertyName: string) => !propertyName.startsWith("$") })

here is the reproduce link https://codesandbox.io/s/swc-emotion-problem-forked-c7fbit?file=/pages/index.tsx

FYI, using babel is working as expected

1reaction
admapopcommented, Jul 27, 2022

@vip30 You’re right actually, just tried it in my sandbox as well. The culprit seems to be shouldForwardProp.

It breaks even if you do plain HTML.

styled("p", {
  shouldForwardProp: (propertyName: string) => !propertyName.startsWith("$")
})

FYI @Brooooooklyn

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade Guide - Next.js
Upgrade Guide. Upgrading from 12 to 13. To update to Next.js version 13, run the following command using your preferred package manager:
Read more >
How to properly configure NextJS 12.2 w/ SWC, Jest, Eslint ...
I am using NextJS with SWC and have "extends": "next" in my .eslintrc file. Parsing error: Cannot find module 'next/babel'. This below is...
Read more >
swc cannot access before initialization - You.com | The search ...
My another project use modify next.js as meta framework, the project run next dev ... emotion: // Don't compile with jest otherwise all...
Read more >
create-next-app - NPM Package Overview - Socket - Socket.dev
Start using Socket to analyze create-next-app and its 0 dependencies to ... Update react-server-dom-webpack: #40356; Fix flight manifest to include all ...
Read more >
next 12.2.0 on Node.js NPM - NewReleases.io
... feat(next-swc): introduce experimental tracing support for swc: #35803; Add initial handling for routing tests: #36635; Fix asPath handling for data ...
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