I was working on a node module, where I would have to check if the user had installed an specific package (that's the logic I have to follow) and if not, install that using child_process.exec
.
That's where the problem appears, even though my script installed the package (node_modules
contains it, also package.json
), if I call require.resolve
again, it says the module does not exist.
For what I found (from node github issues), node has sort of a "cache", where on the first call, if the package is not installed, the cache entry for this package is set to a random value which is not the path to it. Then when you install and try to call that again, it calls that cache entry.
Is there any other way to check if packages are installed, or my local node installation is broken?