79798807

Date: 2025-10-24 13:37:38
Score: 1
Natty:
Report link

When you run npm ls:

[email protected]
+-- [email protected]
`-- [email protected] -> ../common-components
    `-- [email protected]

In other words: npm ls reports it under both packages, but in reality there’s only one copy used.


If you want to verify that only one copy of my-api is being used at runtime

1. Use require.resolve(CommonJS) or import.meta.url(ESM)

Since your project is ESM ("type": "module"), you can do:

// In App.tsx or any example file
import * as MyApi from 'my-api';

console.log('my-api path:', import.meta.resolve ? await import.meta.resolve('my-api') : MyApi);

2. Compare references at runtime

A more React/JS way:

import * as MyApi from 'my-api';
import { something } from '../common-components/src/SomeComponent';

console.log('Same my-api instance?', MyApi === something.__myApiInstance);

3. Quick hack with node_modules paths

Run this in your example app:

node -p "require.resolve('my-api')"
node -p "require.resolve('../common-components/node_modules/my-api')"
Reasons:
  • RegEx Blacklisted phrase (1.5): resolve ?
  • Long answer (-1):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you
  • Low reputation (0.5):
Posted by: ninadepina