Failed to install eslint in a specific situation


(Toru Nagashima) #1

What I Wanted to Do


Installing eslint and it gets installed correctly.

What Happened Instead

npm failed to install eslint.

npm ERR! peer dep missing: acorn@^6.0.0, required by acorn-jsx@5.0.0

Reproduction Steps

# rm -rf node_modules
npm install browser-env eslint


Maybe, this installation fail happens if a package that has acorn@<6.0.0 in that dependencies, regardless direct or indirect, and that name is before eslint in alphabet order exists.

(A trivial issue) `npm ls` is broken.
$ npm ls acorn acorn-jsx
sandbox@7.0.0 C:\Users\t-nagashima.AD\dev\sandbox
+-- browser-env@3.2.5
| `-- window@4.2.5
|   `-- jsdom@11.6.2
|     +-- acorn@5.7.3
|     `-- acorn-globals@4.3.0
|       `-- acorn@6.0.2
`-- eslint@5.7.0
  `-- espree@4.1.0
    `-- acorn-jsx@5.0.0
# ↑ acorn@6.0.2 doesn't display under espree

I guess Installing a package with a mismatching peer dependency causes the peer dependency to disappear from npm ls is this issue.

The directory structure is not correct.

β”œ acorn (5.7.3)
β”œ acorn-jsx (5.0.0) # require acorn@^6.0.0 as a peer dep
β”” espree (4.1.0) # require acorn@^6.0.0
 β”” node_modules
  β”” acorn (6.0.2)

So the acorn-jsx loads acorn@5.7.3 incorrectly even if it requires acorn@^6.0.0.
I guess the acorn-jsx should be in espree/node_modules because it’s a direct dependency of espree and the acorn that espree depends on is pinned on espree/node_modules.

Probably, was the same problem.
In the comment, @zkat said β€œuse npm@2-style installation.”

But npm@6 today.

Platform Info

$ npm --versions
{ sandbox: '7.0.0',
  npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.0',
  http_parser: '2.8.0',
  icu: '61.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.32.0',
  node: '10.5.0',
  openssl: '1.1.0h',
  tz: '2018c',
  unicode: '10.0',
  uv: '1.20.3',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform

packages with peerDependencies are incorrectly hoisted
(system) closed #2

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