在执行 npm i swiper 时出现报错:
npm ERR! code 255
npm ERR! path C:\Users\Emir\Desktop\Project\portal\node_modules\swiper
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c
C:\Users\Emir\AppData\Local\Temp\postinstall-cab5f01a.cmd
npm ERR! "Love Swiper? Support Vladimir's work by donating or pledging on patreon:"
npm ERR! The syntax of the command is incorrect.
解决方案:
1、新开一个终端执行 $env:OPEN_SOURCE_CONTRIBUTOR="true" 绕过相等性测试,但仍旧安装失败
2、npm 时添加 --ignore-scripts 后缀
npm i swiper --ignore-scripts
这样做可以禁止npm里第三方依赖包的预先安装脚本或则安装后脚本被执行,避免一个恶意包里的病毒。
但是也要注意,有些依赖包需要这些预先安装脚本或则安装后脚本来配置环境,加 --ignore-scripts 后缀可能会导致这些依赖包没有正常发挥作用
可以下载 can-i-ignore-scripts 这个包来判断哪些依赖包可以使用 --ignore-scripts 后缀
本文探讨了在执行npm iswiper时遇到的错误255,涉及如何通过新开终端和添加--ignore-scripts选项来解决。提醒读者注意忽略脚本可能带来的潜在问题,并推荐can-i-ignore-scripts工具帮助判断。
527





