Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Find a Second React Copy npm ls Misses

npm ls shows a logical dependency tree, not every module instance. Compare React’s resolved paths from your app and linked packages to find the copy behind an Invalid Hook Call warning.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

npm ls react can show one React version and still miss the second module instance causing an Invalid Hook Call warning. It reports npm’s logical dependency tree—not a definitive inventory of every physical package directory or every module your app loads. Check the full tree, compare React’s resolved paths from each importer, then fix the package metadata or resolver that creates the mismatch.

Why npm ls can miss a second React copy

npm ls describes dependency relationships in npm’s logical tree. That is different from a physical map of every node_modules directory and from the paths a runtime or bundler resolves for imports. Its default output can also be shallow. A linked library or nested package may therefore resolve React from a different location even when the displayed tree appears to show one version. See npm’s ls documentation.

As an Amazon Associate I earn from qualifying purchases.

React’s requirement is about module identity: the react import in application code must resolve to the same module as the import inside react-dom. Identical version labels do not prove that the imports refer to one module. A second React copy can coexist harmlessly in an isolated widget, but it is a problem when code in the same component tree—especially application Hooks and react-dom—uses different React instances. React’s Invalid Hook Call guidance explains the condition.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to check the dependency tree and actual resolution

  1. Show all React dependency paths

    From the application root, run npm ls --all react (or npm ls react --all). The --all flag asks npm to show the full logical tree rather than only the default shallow view. Read the paths and versions as clues, not as proof of which physical module each importer loads.

  2. Inspect placement and links

    Run npm ls -l react to request link information. If the result still leaves the layout unclear, inspect the relevant package directories and their nested node_modules folders directly. npm distinguishes its logical tree from the physical installation layout in the command documentation.

  3. Resolve React from each importing package

    Compare the path resolved from the app with the path resolved from the linked library or workspace package that imports React. In CommonJS, run require.resolve('react') from each package context. If you need to resolve from a particular file, Node provides require.resolve with a paths option; use the importing package’s directory as the search context rather than assuming the app root represents every importer.

    Different resolved paths are evidence of different module identities; the same version text alone is not enough. Node resolves dependencies relative to the calling module and, by default, follows symlinks to real paths. Its module cache is keyed by resolved filename, so distinct resolved paths can produce distinct module instances. See Node.js module documentation.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Check the library’s React declaration

    For a reusable component library, inspect its package.json. React generally belongs in peerDependencies, so the consuming application supplies the React instance, rather than in ordinary dependencies in a way that installs a private copy for the library. React specifically identifies a library that lists React as a dependency instead of a peer dependency as a possible source of duplicate instances. See the React troubleshooting guidance.

Choose a fix based on what the path checks show

What you find What to do What to verify
The component library declares React as an ordinary dependency and resolves its own copy. Correct the library’s package metadata so React is a peer dependency, then install or link the corrected package. Resolve React from both the app and library contexts again; confirm they point to the same module used by react-dom.
Compatible copies exist in the dependency layout. Use npm find-dupes to preview deduplication, or run npm dedupe to reorganize compatible packages. Repeat the importer path checks and test the app. Deduplication does not change semver ranges for direct dependencies in package.json, so it may not solve every mismatch. See npm find-dupes and npm dedupe.
A linked or hoisted package still resolves a different React path because of bundler resolution. Configure the bundler to resolve React consistently from the app where appropriate, while accounting for symlink behavior and build mode. Check the resulting bundle or runtime behavior, not only npm’s tree.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Bundler settings to inspect

Vite

Vite’s resolve.dedupe option can force selected dependencies, such as React, to resolve to one copy from the project root. This can help with hoisted dependencies or linked packages. Vite documents a limitation for SSR builds using ESM outputs configured through build.rollupOptions.output; check the Vite shared options for the behavior applicable to your version and configuration.

webpack

Inspect resolve.alias and resolve.symlinks in the webpack configuration. Aliases take precedence, and webpack’s default symlink behavior resolves linked resources to their real paths. That can change where dependency lookup begins when using npm link. See webpack resolve configuration.

Validate the result

  • Resolve React from the application and every relevant library or workspace importer; compare actual paths, not just package versions.
  • Confirm that the application’s React and the React imported by react-dom share the same module identity.
  • After changing metadata, deduplicating, or adjusting bundler resolution, run the app and check whether the Invalid Hook Call warning is gone.
  • If behavior remains unclear, inspect the installed layout and the bundler’s resolution output; a clean-looking npm tree alone does not establish runtime identity.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.