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.

Error "Identifier '_styled' has already been declared" with styled-components + ts + next.js

See original GitHub issue

Looks 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:

Maybe this is related to https://github.com/ben-rogerson/twin.macro/issues/192?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
coffee-cupcommented, Jul 5, 2021

I am seeing a similar issue after upgrading to the latest twin.macro (2.6.1) from 2.3.3.

I am using

  • twin.macro@2.6.1
  • next@11.0.1
  • styled-components@5.1.0
  • typescript@4.3.4

image

Any idea why it might be happening or any configuration changes I can make to fix it?

2reactions
jeremyzilarcommented, Jul 8, 2021

This works now in 2.6.2, thank you @ben-rogerson 🚀

Read more comments on GitHub >

github_iconTop 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 >

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