Error "Identifier '_styled' has already been declared" with styled-components + ts + next.js
See original GitHub issueLooks like the compiler duplicates the import statement of styled-components
with the one created by the babel macro when mixing <div tw="..." />
usage with tw.div``
.
This happens when using:
- twin.macro
- Nextjs
- styled-components
- Typescript
Error:
Module parse failed: Identifier '_styled' has already been declared (3:7)
File was processed with these loaders:
* ./node_modules/@next/react-refresh-utils/loader.js
* ./node_modules/next/dist/build/webpack/loaders/next-babel-loader.js
You may need an additional loader to handle the result of these loaders.
| import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
| import _styled from "styled-components";
> import _styled from "styled-components";
To reproduce:
- With error: https://github.com/lopezjurip/twin.macro-nextjs-styled-ts-error
- With commented lines to make it work: https://github.com/lopezjurip/twin.macro-nextjs-styled-ts-error/commit/507900c0e295bab5a5408cd8e98fbaffdda2ccf8
Maybe this is related to https://github.com/ben-rogerson/twin.macro/issues/192?
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
Typescript and styled-components gives error on import
js ' implicitly has an 'any' type. To fix this I renamed the file to *.jsx and the problem went away. I'm just...
Read more >Identifier has already been declared Error in JavaScript
The "Identifier has already been declared error" occurs when a variable with the same name has been declared multiple times in the same...
Read more >Solving the Styled Components Warning in Next.JS with Babel
JS and Styled Components is truly epic. You get fast, Static Rendered, highly semantic code as a result of the union, but you...
Read more >Troubleshooting Common Errors - Gatsby
Problems with the cache · Errors with common plugin configurations. Installing plugins for styling results in Generating SSR bundle failed · Errors in...
Read more >Module parse failed: Identifier 'e' has already been declared
I'm able to install and use my library in any react application, when I try to build the react app I'm getting the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am seeing a similar issue after upgrading to the latest twin.macro (2.6.1) from 2.3.3.
I am using
Any idea why it might be happening or any configuration changes I can make to fix it?
This works now in
2.6.2
, thank you @ben-rogerson 🚀