精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
npm是node.js的包管理器,安装依赖包非常方便,但是因为是国外服务器,国内一般用cnpm,是淘宝维护的服务器,在国内安装包用cnpm比npm更快,最近用cnpm安装一个vue平台,遇到了cnpm安装时的奇怪问题,明明安装上了,结果文件找不到,安装了node.js 10,node.js 14,node.js 16都不行,第二天认真看文档,才发现问题,这问题一般人也不会留意,所以给大家说下。
下面是安装时错误日志:
npm install -g cnpm --registry=https://registry.npm.taobao.org npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
下面是另外一次错误的日志:
.\npm install -g cnpm --registry=https://registry.npm.taobao.org npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated har-validator@5.1.5: this library is no longer supported D:\vueProject\nodejs\node_global\cnpm -> D:\vueProject\nodejs\node_global\node_modules\cnpm\bin\cnpm npm WARN notsup Unsupported engine for open@8.4.0: wanted: {"node":">=12"} (current: {"node":"10.24.1","npm":"6.14.12"}) npm WARN notsup Not compatible with your version of node/npm: open@8.4.0 npm WARN notsup Unsupported engine for pacote@12.0.2: wanted: {"node":"^12.13.0 || ^14.15.0 || >=16"} (current: {"node":"10.24.1","npm":"6.14.12"}) npm WARN notsup Not compatible with your version of node/npm: pacote@12.0.2 npm WARN notsup Unsupported engine for npmlog@6.0.0: wanted: {"node":"^12.13.0 || ^14.15.0 || >=16"} (current: {"node":"10.24.1","npm":"6.14.12"}) npm WARN notsup Not compatible with your version of node/npm: npmlog@6.0.0 npm WARN notsup Unsupported engine for gauge@4.0.0: wanted: {"node":"^12.13.0 || ^14.15.0 || >=16"} (current: {"node":"10.24.1","npm":"6.14.12"}) npm WARN notsup Not compatible with your version of node/npm: gauge@4.0.0
上面应该是版本问题,下面是正确的日志:。
+ cnpm@7.1.0 added 54 packages from 12 contributors, removed 15 packages and updated 365 packages in 63.885s
成功了,但是安装的cnpm文件找不到,所以就奇怪了。表现如下图:
看文档里npm config set cache "D:\vueProject\nodejs\node_cache",这里盘符D和nodejs安装盘符E实际不对应,所以出了安装到不存在D盘目录下了,cache就是缓存的意思,会影响shell环境执行命令的硬盘位置,把set cache目录和实际安装目录一致,问题得到解决。
另外在控制台里,直接执行cnpm -v不行, 但是在ideal的控制台里可以,安装vue平台时,第一次cnpm install还没反应, 说包都有,不用安装,用npm install后,再用cnpm install就安装上依赖包了。
我经常用VS C++ C#开发,换个平台,就是换个思维,思维切换需要时间。很多开源文档都认为开发人员是熟手,比如这里的set cache有什么影响,安装时如何如何,文档没有说,这也是产生问题的一个重要原因。