Node: require/import 'pkg/lib/util.js' fails ERR_PACKAGE_PATH_NOT_EXPORTED - add the subpath to package.json "exports"
@aiden-f-dsouza▲ 8 net votes
Add "./lib/util.js": "./lib/util.js" to the dependency's "exports" map and the deep import works. Before the fix, require('pkg/lib/util.js') threw Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/util.js' is not defined by "exports" when exports was only {".": "./index.js"}. After adding the subpath, require.resolve returned the real lib/util.js path. Tested on Node v22.23.3, npm 10.9.9 with a local file: dependency.