Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twin.macro errors when moving from Babel to SWC #664

Closed
tettoffensive opened this issue Apr 16, 2022 · 6 comments
Closed

twin.macro errors when moving from Babel to SWC #664

tettoffensive opened this issue Apr 16, 2022 · 6 comments

Comments

@tettoffensive
Copy link

Something I ran into when upgrading to Next.js 12 which is moving from Babel to SWC. It seems that emotion and styled-components are being ported, but twin.macro doesn't seem to work. Not sure what the issue is, as I don't really understand what moving from Babel to SWC means

error - ./node_modules/import-fresh/node_modules/resolve-from/index.js:3:0
Module not found: Can't resolve 'module'

Import trace for requested module:
./node_modules/import-fresh/index.js
./node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist/loaders.js
./node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist/index.js
./node_modules/babel-plugin-macros/dist/index.js
./node_modules/twin.macro/macro.js
./pages/_app.tsx

The line in my ./pages/_app.tsx is:

import { GlobalStyles } from 'twin.macro';

After removing this I was also seeing errors with twin.macro's theme:

backgroundColor: twin_macro__WEBPACK_IMPORTED_MODULE_4__.theme`colors.background`
                                                                              
TypeError: twin_macro__WEBPACK_IMPORTED_MODULE_4__.theme is not a function
@kpratik2015
Copy link

Sadly twin.macro doesn't support SWC #516 (comment)

@tettoffensive
Copy link
Author

Exactly. Just wanted to note it, in hopes of it happening someday.

@ben-rogerson
Copy link
Owner

Yep big job supporting SWC Stuart - we'd need babel-plugin-macros written in Rust and then twin would need to be decoupled (split into different packages) from babel. Thinking we're more likely to get an ESBuild plugin at this stage.

Closing in favor of the existing discussion

@ben-rogerson
Copy link
Owner

I've updated the twin examples with a new workaround that'll keep SWC enabled - ref

@sebmellen
Copy link

@ben-rogerson that deserves some celebration 🙌

@fredrivett
Copy link

fredrivett commented Jan 25, 2023

Thanks for this @ben-rogerson, just what I needed!

The link above didn't work as expected though, here's the correct links:

JavaScript | TypeScript

I spent an hour wondering why my config wasn't working when I was trying to use the JS example rather than the TS one, hopefully someone can avoid repeating my ineptitude and pain 🤦🏻‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants