I am working on a project using an NPM monorepo structure which utilizes ECMAScript Modules (ESM):
<root>
|_package.json
|_node_modules/
| |_luxon (1.28.0)
|_packages/
|_pack1
| |_node_modules/
| | |_luxon (3.0.1)
| |_main.js
|_pack2
|_node_modules/
|_main.js
Currently, I am looking for a solution to retrieve the module path from any of my main.js
files:
For example, with two versions of luxon
installed (in root and pack1), when running main.js
from pack1
, here is what I want to achieve:
const luxonPath = (???)("luxon");
// luxonPath should be <root>/packages/pack1/node_modules/luxon
And if running it from pack2
:
const luxonPath = (???)("luxon");
// luxonPath should be <root>/node_modules/luxon