场景重现
npm install --verbose
安装依赖的时,出现如下警告
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
- npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
- npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS: darwin
- npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: any
- npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS: win32
- npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
释疑
这不是什么真的有问题,只是你的某些包依赖fsevents
包,而fsevents
包是MacOS系统下,在Windows/Linux下会提示警告,但不会安装.
解决办法
但是强迫症患者表示不能接受,换个角度看释疑,意味着fsevents
在MacOS下是必须的,而在Windows/Linux下是可选的.
那么我们可以通过package.json
的optionalDependencies
来规避警告,然后npm install --no-optional --verbose
不安装可选项即可.
参考如下:
- {
- "dependencies": {
- "axios": "^0.18.0",
- "echarts": "^4.2.0-rc.2",
- "element-ui": "^2.4.11",
- "screenfull": "^3.3.3",
- "vue": "^2.5.17",
- "vue-router": "^3.0.1",
- "vuex": "^3.0.1"
- },
- "devDependencies": {
- "@vue/cli-plugin-babel": "^3.0.5",
- "@vue/cli-service": "^3.0.5",
- "less": "^3.0.4",
- "less-loader": "^4.1.0",
- "vue-template-compiler": "^2.5.17"
- },
- "optionalDependencies": {
- "fsevents": "*"
- }
- }