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

Phantom dependency / missing peer dependency on @types/react #230

Open
kcon-stackav opened this issue Mar 10, 2025 · 0 comments
Open

Phantom dependency / missing peer dependency on @types/react #230

kcon-stackav opened this issue Mar 10, 2025 · 0 comments

Comments

@kcon-stackav
Copy link

I ran into pnpm/pnpm#7158 while using react-mosaic-component in a monorepo managed by pnpm that uses multiple different versions of react.

In this environment, even though I'm trying to use react-mosaic-component with react@18 and @types/react@18 in a sub-project's package.json, typescript picks up and uses @types/react@19 from the monorepo's root package.json file instead, leading to an error like the following (among others):

error TS2339: Property 'mosaicActions' does not exist on type 'unknown'.

for code like this:

import React, {
  useContext,
} from "react";
import {
  MosaicContext,
} from "react-mosaic-component";

...

const { mosaicActions } = useContext(MosaicContext);

as observed by hovering over the 'react' literal in the import React from 'react' import line in my project's copy of node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_r_5e51779fec180380ca3b15fa496dbe8d/node_modules/react-mosaic-component/lib/contextTypes.d.ts in VS Code and seeing the TypeScript intellisense report:

module "<MY_PROJECT>/node_modules/.pnpm/@[email protected]/node_modules/@types/react/index"

From pnpm/pnpm#7158 (comment) I understand the issue may be that react-mosaic-component does not declare a peer dependency on @types/react (but rather just a dev dependency):

I've found that this is caused by third-party packages which include type declarations that use react types and have a phantom dependency on @types/react. These packages should list @types/react in peerDependencies but it's fairly common for them to have it only as dev dependency, because with npm's hoisting behavior that phantom dependency typically won't cause issues.

And sure enough if I add the following to my root package.json file then all of the errors disappear and my builds/tests pass:

"packageExtensions": {
  "react-mosaic-component": {
    "peerDependencies": {
      "@types/react": "*"
    }
  }
}

Would you consider adding a peer dependency on @types/react to this project's package.json file so we could avoid these errors? 🙏

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

1 participant