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

  1. 有个项目在mac下开发,安装包npm i,一切正常;
  2. 把这个项目放到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 [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    npm WARN [email protected] No description
    npm WARN [email protected] No repository field.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (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: [email protected] (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: [email protected] (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: [email protected] (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: [email protected] (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: [email protected] (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的模块,最后还报了一堆错:

    │   ├── [email protected] deduped
    │   ├── [email protected] deduped
    │   ├── [email protected] deduped
    │   └─┬ [email protected]
    │     └── [email protected]
    ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │ ├── [email protected]
    │ └─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├─┬ UNMET DEPENDENCY [email protected]
    │   │ └── UNMET DEPENDENCY [email protected]
    │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ └─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │   └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ └─┬ UNMET DEPENDENCY [email protected]
    │   │ │   └─┬ UNMET DEPENDENCY [email protected]
    │   │ │     ├── UNMET DEPENDENCY [email protected]
    │   │ │     └── UNMET DEPENDENCY [email protected]
    │   │ └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ └─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │   ├── UNMET DEPENDENCY [email protected]
    │   │ │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │   ├── UNMET DEPENDENCY [email protected]
    │   │ │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │   │ └── UNMET DEPENDENCY [email protected]
    │   │ │   └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├── UNMET DEPENDENCY [email protected]
    │   │ ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ ├── UNMET DEPENDENCY [email protected]
    │   │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │ ├─┬ UNMET DEPENDENCY [email protected]
    │   │ │ │ ├── UNMET DEPENDENCY [email protected]
    │   │ │ │ ├─┬ UNMET DEPENDENCY [email protected]
    │   │ │ │ │ └── UNMET DEPENDENCY [email protected]
    │   │ │ │ └── UNMET DEPENDENCY [email protected]
    │   │ │ ├─┬ UNMET DEPENDENCY [email protected]
    │   │ │ │ └── UNMET DEPENDENCY [email protected]
    │   │ │ └─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ │   └── UNMET DEPENDENCY [email protected]
    │   │ └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │ └─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   │   ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │   │   │ ├── UNMET DEPENDENCY [email protected]
    │   │   │ └── UNMET DEPENDENCY [email protected]
    │   │   ├── UNMET DEPENDENCY [email protected]
    │   │   ├── UNMET DEPENDENCY [email protected]
    │   │   ├─┬ UNMET DEPENDENCY [email protected]
    │   │   │ └── UNMET DEPENDENCY [email protected]
    │   │   └── UNMET OPTIONAL DEPENDENCY [email protected]
    │   ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │   └─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │     ├── UNMET OPTIONAL DEPENDENCY [email protected]
    │     ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │     │ └── UNMET DEPENDENCY [email protected]
    │     ├─┬ UNMET DEPENDENCY [email protected]
    │     │ ├── UNMET DEPENDENCY [email protected]
    │     │ └── UNMET DEPENDENCY [email protected]
    │     ├─┬ UNMET OPTIONAL DEPENDENCY [email protected]
    │     │ └── UNMET DEPENDENCY [email protected]
    │     ├── UNMET DEPENDENCY [email protected]
    │     ├── UNMET DEPENDENCY [email protected]
    │     └── UNMET DEPENDENCY [email protected]
    ├─┬ [email protected]
    │ ├─┬ [email protected]
    │ │ └── [email protected] deduped
    │ └── [email protected]
    ├── [email protected]
    ├─┬ [email protected]
    │ └── [email protected]
    ├─┬ [email protected]
    │ └── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├─┬ [email protected]
    │ ├── [email protected]
    │ ├── [email protected] deduped
    │ └─┬ [email protected]
    │   ├── [email protected]
    │   ├── [email protected] deduped
    │   ├── [email protected]
    │   ├── [email protected]
    │   ├── [email protected]
    │   ├─┬ [email protected]
    │   │ └── [email protected] deduped
    │   └── [email protected]
    └── [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]
    npm ERR! missing: [email protected], required by [email protected]

    仔细观察发现UNMET OPTIONAL DEPENDENCY的模块和npm ERR是同一批模块,也是安装时报warning的那些模块。

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

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

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

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

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

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

    └─┬ [email protected]
    └── [email protected]

    干净了,没有任何报错。

    我的项目是chokidar这个模块依赖了fseventschokidar又是browser-syncwebpack等依赖的。

相关推荐