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.

Identifier 'React' has already been declared with multiple external libraries

See original GitHub issue

What version of Remix are you using?

1.4.1

Steps to Reproduce

More Details: React Version: 18 Yarn

  • Install remix for cloudflare pages setup
  • Add libraries like (react-spring, framer-motion, react-hook/mouse-postion)
  • Use them (simple import is enough)

Expected Behavior

Application/Website loads correctly when running wrangler pages dev ./public and remix watch

Actual Behavior

Website loads, shows for a few ms, then breaks. Console sends multiple errors:

Uncaught SyntaxError: Identifier 'React' has already been declared
Uncaught Error: Cannot initialize 'routeModules'. This normally occurs when you have server code in your client modules.
Hydration failed because the initial UI does not match what was rendered on the server.
react-dom.development.js:86 Warning: An error occurred during hydration. The server HTML was replaced with client content in <#document>.

The first error shows the error into the installed packages from above, always the same line (the first react import) var React = __toESM(require_react());

This happens to a lot of modules. You can fix that by renaming React to something else within the package and patching those with npx patch-package. But this makes things hard as you have to patch a lot of packages. It looks like something is going wrong during compilation (which naturally is part of remix - non-configurable).

Can somebody reproduce this issue?

Edit: Node Version: v16.13.2 Mac M1 Max

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:8
  • Comments:43 (11 by maintainers)

github_iconTop GitHub Comments

14reactions
chaancecommented, Jul 5, 2022

So does this mean a fix isn’t possible for now or this is a “won’t fix” type of issue?

Definitely looking to fix this. It’s still at the top of my priority list.

6reactions
chaancecommented, Aug 24, 2022

Looks like we were finally able to get this resolved! Updated to v1.7.0-pre.0 here and everything runs swimmingly. We should be able to close this after the stable release is published 🥳

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing error: Identifier 'React' has already been declared
On the top of code snippet React is imported twice import React from 'react'; import React,{Component} from 'react';. It should be
Read more >
Integrating with Other Libraries
This guide will examine some of the more common use cases, focusing on integration with jQuery and Backbone, but the same ideas can...
Read more >
Module parse failed: Identifier 'e' has already been declared
I'm building a reusable component. The component uses @arcgis/core along with other ui. I'm able to install and use my library in any...
Read more >
Modern JavaScript – Imports, Exports, Let, Const, and ...
Over the past few years, there have been many updates to the ... to learn a JavaScript library like React or framework like...
Read more >
MDX and React
Using the power of React in Docusaurus Markdown documents, thanks to MDX. ... To define any custom component within an MDX file, you...
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