欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

详解linux下fsevents模块引起的npm ls报错解决办法

程序员文章站 2022-07-09 16:58:36
有个项目在mac下开发,安装包npm i,一切正常; 把这个项目放到linux机器上,安装包npm i,报了一堆warning: npm warn opti...

有个项目在mac下开发,安装包npm i,一切正常;

把这个项目放到linux机器上,安装包npm i,报了一堆warning:

npm warn optional skipping optional dependency: fsevents@^1.2.7 (node_modules/chokidar/node_modules/fsevents):
npm warn notsup skipping optional dependency: unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm warn 0403@1.0.0 no description
npm warn 0403@1.0.0 no repository field.
npm warn optional skipping optional dependency: abbrev@1.1.1 (node_modules/fsevents/node_modules/abbrev):
npm warn enoent skipping optional dependency: enoent: no such file or directory, rename '/root/2019/0403/node_modules/fsevents/node_modules/abbrev' -> '/root/2019/0403/node_modules/fsevents/node_modules/.abbrev.delete'
npm warn optional skipping optional dependency: ansi-regex@2.1.1 (node_modules/fsevents/node_modules/ansi-regex):
npm warn enoent skipping optional dependency: enoent: no such file or directory, rename '/root/2019/0403/node_modules/fsevents/node_modules/ansi-regex' -> '/root/2019/0403/node_modules/fsevents/node_modules/.ansi-regex.delete'
npm warn optional skipping optional dependency: aproba@1.2.0 (node_modules/fsevents/node_modules/aproba):
npm warn enoent skipping optional dependency: enoent: no such file or directory, rename '/root/2019/0403/node_modules/fsevents/node_modules/aproba' -> '/root/2019/0403/node_modules/fsevents/node_modules/.aproba.delete'
npm warn optional skipping optional dependency: balanced-match@1.0.0 (node_modules/fsevents/node_modules/balanced-match):
npm warn enoent skipping optional dependency: enoent: no such file or directory, rename '/root/2019/0403/node_modules/fsevents/node_modules/balanced-match' -> '/root/2019/0403/node_modules/fsevents/node_modules/.balanced-match.delete'
npm warn optional skipping optional dependency: chownr@1.1.1 (node_modules/fsevents/node_modules/chownr):
npm warn enoent skipping optional dependency: enoent: no such file or directory, rename '/root/2019/0403/node_modules/fsevents/node_modules/chownr' -> '/root/2019/0403/node_modules/fsevents/node_modules/.chownr.delete'
npm warn optional skipping optional dependency: code-point-at@1.1.0 (node_modules/fsevents/node_modules/code-point-at):
npm warn enoent skipping optional dependency: enoent: no such file or directory, rename '/root/2019/0403/node_modules/fsevents/node_modules/code-point-at' -> '/root/2019/0403/node_modules/fsevents/node_modules/.code-point-at.delete'
...

执行npm ls,有不少unmet optional dependency的模块,最后还报了一堆错:

│  ├── define-property@2.0.2 deduped
│  ├── extend-shallow@3.0.2 deduped
│  ├── regex-not@1.0.2 deduped
│  └─┬ safe-regex@1.1.0
│   └── ret@0.1.15
├─┬ unmet optional dependency fsevents@1.2.7
│ ├── nan@2.13.2
│ └─┬ unmet optional dependency node-pre-gyp@0.10.3
│  ├── unmet optional dependency detect-libc@1.0.3
│  ├─┬ unmet dependency mkdirp@0.5.1
│  │ └── unmet dependency minimist@0.0.8
│  ├─┬ unmet optional dependency needle@2.2.4
│  │ ├─┬ unmet optional dependency debug@2.6.9
│  │ │ └── unmet optional dependency ms@2.0.0
│  │ ├─┬ unmet optional dependency iconv-lite@0.4.24
│  │ │ └── unmet optional dependency safer-buffer@2.1.2
│  │ └── unmet optional dependency sax@1.2.4
│  ├─┬ unmet optional dependency nopt@4.0.1
│  │ ├── unmet optional dependency abbrev@1.1.1
│  │ └─┬ unmet optional dependency osenv@0.1.5
│  │  ├── unmet optional dependency os-homedir@1.0.2
│  │  └── unmet optional dependency os-tmpdir@1.0.2
│  ├─┬ unmet optional dependency npm-packlist@1.2.0
│  │ ├─┬ unmet optional dependency ignore-walk@3.0.1
│  │ │ └─┬ unmet dependency minimatch@3.0.4
│  │ │  └─┬ unmet dependency brace-expansion@1.1.11
│  │ │   ├── unmet dependency balanced-match@1.0.0
│  │ │   └── unmet dependency concat-map@0.0.1
│  │ └── unmet optional dependency npm-bundled@1.0.5
│  ├─┬ unmet optional dependency npmlog@4.1.2
│  │ ├─┬ unmet optional dependency are-we-there-yet@1.1.5
│  │ │ ├── unmet optional dependency delegates@1.0.0
│  │ │ └─┬ unmet optional dependency readable-stream@2.3.6
│  │ │  ├── unmet optional dependency core-util-is@1.0.2
│  │ │  ├── unmet dependency inherits@2.0.3
│  │ │  ├── unmet optional dependency isarray@1.0.0
│  │ │  ├── unmet optional dependency process-nextick-args@2.0.0
│  │ │  ├── unmet dependency safe-buffer@5.1.2
│  │ │  ├─┬ unmet optional dependency string_decoder@1.1.1
│  │ │  │ └── unmet dependency safe-buffer@5.1.2
│  │ │  └── unmet optional dependency util-deprecate@1.0.2
│  │ ├── unmet dependency console-control-strings@1.1.0
│  │ ├─┬ unmet optional dependency gauge@2.7.4
│  │ │ ├── unmet optional dependency aproba@1.2.0
│  │ │ ├── unmet dependency console-control-strings@1.1.0
│  │ │ ├── unmet optional dependency has-unicode@2.0.1
│  │ │ ├── unmet optional dependency object-assign@4.1.1
│  │ │ ├── unmet optional dependency signal-exit@3.0.2
│  │ │ ├─┬ unmet dependency string-width@1.0.2
│  │ │ │ ├── unmet dependency code-point-at@1.1.0
│  │ │ │ ├─┬ unmet dependency is-fullwidth-code-point@1.0.0
│  │ │ │ │ └── unmet dependency number-is-nan@1.0.1
│  │ │ │ └── unmet dependency strip-ansi@3.0.1
│  │ │ ├─┬ unmet dependency strip-ansi@3.0.1
│  │ │ │ └── unmet dependency ansi-regex@2.1.1
│  │ │ └─┬ unmet optional dependency wide-align@1.1.3
│  │ │  └── unmet dependency string-width@1.0.2
│  │ └── unmet optional dependency set-blocking@2.0.0
│  ├─┬ unmet optional dependency rc@1.2.8
│  │ ├── unmet optional dependency deep-extend@0.6.0
│  │ ├── unmet optional dependency ini@1.3.5
│  │ ├── unmet optional dependency minimist@1.2.0
│  │ └── unmet optional dependency strip-json-comments@2.0.1
│  ├─┬ unmet optional dependency rimraf@2.6.3
│  │ └─┬ unmet optional dependency glob@7.1.3
│  │  ├── unmet optional dependency fs.realpath@1.0.0
│  │  ├─┬ unmet optional dependency inflight@1.0.6
│  │  │ ├── unmet dependency once@1.4.0
│  │  │ └── unmet dependency wrappy@1.0.2
│  │  ├── unmet dependency inherits@2.0.3
│  │  ├── unmet dependency minimatch@3.0.4
│  │  ├─┬ unmet dependency once@1.4.0
│  │  │ └── unmet dependency wrappy@1.0.2
│  │  └── unmet optional dependency path-is-absolute@1.0.1
│  ├── unmet optional dependency semver@5.6.0
│  └─┬ unmet optional dependency tar@4.4.8
│   ├── unmet optional dependency chownr@1.1.1
│   ├─┬ unmet optional dependency fs-minipass@1.2.5
│   │ └── unmet dependency minipass@2.3.5
│   ├─┬ unmet dependency minipass@2.3.5
│   │ ├── unmet dependency safe-buffer@5.1.2
│   │ └── unmet dependency yallist@3.0.3
│   ├─┬ unmet optional dependency minizlib@1.2.1
│   │ └── unmet dependency minipass@2.3.5
│   ├── unmet dependency mkdirp@0.5.1
│   ├── unmet dependency safe-buffer@5.1.2
│   └── unmet dependency yallist@3.0.3
├─┬ glob-parent@3.1.0
│ ├─┬ is-glob@3.1.0
│ │ └── is-extglob@2.1.1 deduped
│ └── path-dirname@1.0.2
├── inherits@2.0.3
├─┬ is-binary-path@1.0.1
│ └── binary-extensions@1.13.1
├─┬ is-glob@4.0.1
│ └── is-extglob@2.1.1
├── normalize-path@3.0.0
├── path-is-absolute@1.0.1
├─┬ readdirp@2.2.1
│ ├── graceful-fs@4.1.15
│ ├── micromatch@3.1.10 deduped
│ └─┬ readable-stream@2.3.6
│  ├── core-util-is@1.0.2
│  ├── inherits@2.0.3 deduped
│  ├── isarray@1.0.0
│  ├── process-nextick-args@2.0.0
│  ├── safe-buffer@5.1.2
│  ├─┬ string_decoder@1.1.1
│  │ └── safe-buffer@5.1.2 deduped
│  └── util-deprecate@1.0.2
└── upath@1.1.2
npm err! missing: mkdirp@0.5.1, required by node-pre-gyp@0.10.3
npm err! missing: minimist@0.0.8, required by mkdirp@0.5.1
npm err! missing: minimatch@3.0.4, required by ignore-walk@3.0.1
npm err! missing: brace-expansion@1.1.11, required by minimatch@3.0.4
npm err! missing: balanced-match@1.0.0, required by brace-expansion@1.1.11
npm err! missing: concat-map@0.0.1, required by brace-expansion@1.1.11
npm err! missing: console-control-strings@1.1.0, required by npmlog@4.1.2
npm err! missing: inherits@2.0.3, required by readable-stream@2.3.6
npm err! missing: safe-buffer@5.1.2, required by readable-stream@2.3.6
npm err! missing: safe-buffer@5.1.2, required by string_decoder@1.1.1
npm err! missing: console-control-strings@1.1.0, required by gauge@2.7.4
npm err! missing: string-width@1.0.2, required by gauge@2.7.4
npm err! missing: strip-ansi@3.0.1, required by gauge@2.7.4
npm err! missing: code-point-at@1.1.0, required by string-width@1.0.2
npm err! missing: is-fullwidth-code-point@1.0.0, required by string-width@1.0.2
npm err! missing: strip-ansi@3.0.1, required by string-width@1.0.2
npm err! missing: number-is-nan@1.0.1, required by is-fullwidth-code-point@1.0.0
npm err! missing: ansi-regex@2.1.1, required by strip-ansi@3.0.1
npm err! missing: string-width@1.0.2, required by wide-align@1.1.3
npm err! missing: inherits@2.0.3, required by glob@7.1.3
npm err! missing: minimatch@3.0.4, required by glob@7.1.3
npm err! missing: once@1.4.0, required by glob@7.1.3
npm err! missing: once@1.4.0, required by inflight@1.0.6
npm err! missing: wrappy@1.0.2, required by inflight@1.0.6
npm err! missing: wrappy@1.0.2, required by once@1.4.0
npm err! missing: minipass@2.3.5, required by tar@4.4.8
npm err! missing: mkdirp@0.5.1, required by tar@4.4.8
npm err! missing: safe-buffer@5.1.2, required by tar@4.4.8
npm err! missing: yallist@3.0.3, required by tar@4.4.8
npm err! missing: minipass@2.3.5, required by fs-minipass@1.2.5
npm err! missing: safe-buffer@5.1.2, required by minipass@2.3.5
npm err! missing: yallist@3.0.3, required by minipass@2.3.5
npm err! missing: minipass@2.3.5, required by minizlib@1.2.1

仔细观察发现unmet optional dependency的模块和npm err是同一批模块,也是安装时报warning的那些模块。

再仔细观察发现这些都是fsevents依赖的模块。

fsevents只能在macos下安装,无法在linux系统安装。linux下会跳过fsevents模块,也不会安装fsevents依赖的模块。

这其实算是npm的一个bug,npm i时报warn,npm ls又报err,前后不一致,容易有误解。

目前无论用哪个版本的npm都会有这个问题,npm i --no-optional也不能解决这个问题。

这些报错不影响项目的正常运行,因为linux不需要fsevents。

如果不希望看到npm err,可以用npm i -f强制安装,安装过程没有warn,安装完后npm ls看下:

└─┬ chokidar@2.1.5
└── fsevents@1.2.7 

干净了,没有任何报错。

我的项目是chokidar这个模块依赖了fsevents,chokidar又是browser-sync、webpack等依赖的。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。