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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.