Make `npm install` dedupe (flatten) by default

Viewed 532

I made this sample directory example:

packages/
   package1/
     -- this has lodash as dependencies
   package2/
     -- this has package1 as dependencies using file:///path/to/packages/package1

When I do npm install inside package2 my directory hierarchy is

package2/
  node_modules/
    package1/
      node_modules/
        lodash/

If I run npm dedupe after, then the directory becomes:

package2/
  node_modules/
    package1/
    lodash/

On the other hand, if I do yarn install, then I get the flattened directory by default. How can I make both npm install and yarn install behave the same? npm dedupe is incredibly slow and not practical in a real application.

This is more than just a matter of convenience - I currently have a script package and I want to move common dependencies into it. However, if the structure is not flattened, then if I do require('some-package') inside this scripts repo, I get module not found because the package is nested.

1 Answers
Related