Get a path to NPM package without entry point

A unconventional package contains a binary and nested modules but no entry point (no index script and no main), react-scripts is an example.

require.resolve('react-scripts/bin/react-scripts') works because bin/react-scripts.js module exists but require.resolve('react-scripts') results in error because the package has no entry point.

It’s preferable to avoid relying on an expected location like ./node_modules/react-scripts because it depends on project structure.

What is a good way to get full path to react-scripts module folder?

Answer

It’s possible to extract package path from a nearest file that is expected to exist, which is package.json:

path.dirname(require.resolve('react-scripts/package.json'))

Still would appreciate alternative approaches to resolving a path to the the package.