0

I'm kind of lost here!

I'm using a module which has another module nested in its' node_modules. I.E.

my_project
    node_modules
        widely_used_module
        parent_dependency
            node_modules
               widely_used_module

I have some fixes in my "own" widely_used_module (it could be just a minor version from the original distributor, but to be completely honest, in this case its' my fork on Github containing some critical fixes).

When I manually remove node_modules/parent_dependency/node_modules, parent_dependency starts to reference to my "widely used module" instead of its' own. But this of course gets overriden once I hit npm install again.

  1. Can I somehow prevent a package to install its' own modules, or can I force a package to reference the root node_modules and ignore its' own?
  2. Is that even the right approach to fixing such issues? I don't want to fork parent_dependency as well...

Thank you

noamyg
  • 2,747
  • 1
  • 23
  • 44
  • 1
    is it helpful? https://stackoverflow.com/questions/15806152/how-do-i-override-nested-npm-dependency-versions – Hardik Modha Dec 13 '18 at 14:47
  • @HardikModha maybe I should read more about it, but it seems that when I remove the descendant dependencies from either `package-lock.json` or `npm-shrinkwrap.json` they are being retrieved as soon as I `npm install` again. – noamyg Dec 13 '18 at 15:23

1 Answers1

0

Answering my own question; Yarn has a built-in solution for this exact issue. This could be achievable with NPM as well but yarn made it so easy to fix that I moved the project dependencies to be handled by yarn.

Full solution:

  1. Installing yarn
  2. Ran yarn in project's root path
  3. Removed package.lock.json
  4. Added resolutions to my package.json. In my case:

    { "dependencies": { "...": "...", "parent_dependency": "^x.y.z" }, "devDependencies": { "...": "..." }, "resolutions": { "parent_dependency/widely_used_module": "git+https://git@github.com/myuser/widely_used_module.git" } }

  5. Ran yarn install.

Result: No more widely_used_module folder under parent_dependency.

noamyg
  • 2,747
  • 1
  • 23
  • 44