npm does not flatten packages during install

What I Wanted to Do

I wanted to extract constantly repeated babel dependency from multiple projects into one dependency,
and have dependencies managed in a separate package

What Happened Instead

After creating the package and adding it to the dependency list, I see that @babel/core is not available for a target application. After npm dedupe it is visible again

Because of dedupe is not user-friendly for the big project I started to use yarn again that flattens packages during install.

Also, consider that having some big packages multiple times is redundant and I think it is preferable to have packages immediately available in the flat structure, instead of having a tree with duplicates.

Reproduction Steps & Details

The same issue described here: https://github.com/npm/npm/issues/19770

Platform Info

$ npm --versions
{ network_components: '0.0.1',
  npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.14.2',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.45',
  zlib: '1.2.11' }
$ node -p process.platform
<darwin

Can you check if a second run of npm install fixes the issue too? If so, it might be related to need to run `npm install` twice.

I will create a simple reproduction steps scenario, and will inform here

No, double npm install does not resolve the issue

Part of my main package looks like this:

    "tool-jest-babel": "../../_deps/tool-jest-babel/",
    "tool-lint-react": "../../_deps/tool-lint-react/",
    "tool-prettier": "file:../../_deps/tool-prettier",
    "tool-rollup-react": "file:../../_deps/tool-rollup-react",
    "tool-story-react": "file:../../_deps/tool-story-react"

So what NPM does is that it install node_modules in each of these folders and the package that has babel stuff is located under the node_modules/tool-rollup-react/node_modules/with-babel/node_modules/@babel/core

When I want to have this

  • node_modules/@babel/core
  • node_modules/tool-rollup-react
  • node_modules/with-babel/

So basically npm on purpose creates a tree of modules, and if it is file:../relative_path_in_the_project it will install there node_modules as well, though I don’t want to…

Yarn handles this just right, no unnecessary node_modules and all packages are flat from the very beginning.

Tell me if a reproduction example is still required

P.S.: sorry for some bad english sentence building… Should definitely work on that matter ;)

Any news or plans on this feature/issue ? Thank you!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.