Thursday, 1 June 2017

How to require.resolve the package directory?

require.resolve('babel-runtime') returns an error because its package.json does not contain a "main" field. However, I'm not interested in the main/entry file of the package, I want to get the directory of the package itself.

Usually that's located at ${__dirname}/node_modules/babel-runtime, but it might not be if the node_modules tree is flattened. So how can I resolve the directory of a package the same way Node knows where to look when you write something like require('babel-runtime/core-js/object/create')?



via mpen

No comments:

Post a Comment