I have a project with multiple node_modules directories
myproj |-->app1 package.json |-->node_modules |-->src |-->origapp_reactnative package.json |-->node_modules |-->shared_src |-->app2 package.json |-->node_modules |-->src When bulding app1 or app2 with webpack (from their respecitive root dirs.). I must specify
resolve.modules=[path.resolve(__dirname,"./node_modules")] If I do not do that, then webpack will try to pull code from
|-->origapp_reactnative |-->node_modules Because app1 or app2 include sources from shared_src. And webpack tries to follow nodejs convention and look for node_modules in the dir next to shared_src.
So that's why I am setting resolve.modules to an absolute path.
However, that creates another problem, that I cannot overcome: webpack flattens the dependency tree within node_modules specified by absolute path. And that creates dependency problem, where modules of different versions cannot coexist.
So I am looking for a way to use, therefore, relative path
resolve.modules=["./node_modules"] But need help to figure out how to exclude the node_modules
|-->origapp_reactnative |-->node_modules from webpacks consideration.
( I have tried to instruct babel loader as discussed here [1], not to look there -- but that's not enough, because compilation still will fails. )