亲宝软件园·资讯

展开

关于npm主版本升级及其相关知识点总结

pulledup 人气:0

前言

在windows下,由于操作系统版本不同,导致node.js的版本范围受限,再导致默认下载npm的版本受限,再导致其所管理的注册“包”的版本不一致......

MSWindows平台,目前企业主要在用的OS版本有:Win7/Windows Server 2008; Win8/Windows Server 2012; Win10/Windows Server 2016~2019、及其以上的Win11/Windows Server 2020。

特别是在Win7下,问题比较明显。

那么为啥还用win7呢,放弃不就完事儿了?!那是因为其底层内核一致的服务器操作系统Windows Server 2008还广泛地应用于民间(虽然2021年末微软已宣布3*4年生命周期的该产品已不再“售后”维护支持),用win7开发出的代码,运行时将会有更好的兼容性,就好比win7下的App一定在Win10下跑不出问题,但Win10下的App在Win7跑可能就会出问题,微软产品总之向下兼容的。你不可能强迫要求用户单位换服务器,就好比vue2项目、产品、平台,还广泛地应用于民间一样,你不可能强迫要求用户升级为vue3,你不可能强迫要求“软件开发机构”升级到vue3(因为这种升级是有“成本”代价的)。

1、关于npm主版本升级

 
 
 
 
   ╭────────────────────────────────────────────────────────────────╮
   │                                                                │
   │      New major version of npm available! 6.14.4 -> 8.19.2      │
   │   Changelog: https://github.com/npm/cli/releases/tag/v8.19.2   │
   │               Run npm install -g npm to update!                │
   │                                                                │
   ╰────────────────────────────────────────────────────────────────╯

升级前,一定需要关注项目依赖及开发依赖,是否也已经更新到了新版npm......

2、项目上下文 局部安装 开发依赖

npm i -d
npm info it worked if it ends with ok
npm info using npm@6.14.4
npm info using node@v13.14.0
npm info lifecycle my-site@0.1.0~preinstall: my-site@0.1.0
npm timing stage:loadCurrentTree Completed in 30ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1693ms
npm http fetch GET 200 https://registry.npmmirror.com/vue-loader 202ms (from cache)
npm http fetch GET 200 https://registry.npmmirror.com/loader-utils 544ms (from cache)
npm http fetch GET 304 https://registry.npmmirror.com/chalk 841ms (from cache)
npm http fetch GET 200 https://registry.npmmirror.com/ansi-styles 53ms (from cache)
npm http fetch GET 304 https://registry.npmmirror.com/supports-color 103ms (from cache)
npm http fetch GET 304 https://registry.npmmirror.com/color-convert 1000ms (from cache)
npm http fetch GET 304 https://registry.npmmirror.com/color-name 99ms (from cache)
npm http fetch GET 304 https://registry.npmmirror.com/has-flag 92ms (from cache)
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 5431ms
npm timing stage:loadIdealTree Completed in 8039ms
npm timing stage:generateActionsToTake Completed in 1666ms
npm timing audit submit Completed in 12554ms
npm http fetch POST 301 https://registry.npm.taobao.org/-/npm/v1/security/audits/quick 14610ms
[          ........] / extract:is-wsl: sill tarball trying mixin-deep@1.3.2 by hash: sha1-ESC0PcNZp4Xc5ltVuC4lfM9HlWY=

3、mockjs版本兼容性

PS L:\Vue3Test\MyVue3Proj1\my-site> npm i mockjs@^1.1.0
npm WARN notsup Unsupported engine for commander@9.4.0: wanted: {"node":"^12.20.0 || >=14"} (current: {"node":"13.14.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: commander@9.4.0

以下“第4、点” 为连带反应。

简单解决办法:将事前下载好的,上下文中的node_modules\下,做覆盖

4、mockJS对node(及其集成安装的npm)版本的兼容性

导致项目分发时 npm run build时总是弹出这个链接,其中内容为mockJS

> npm run build
 
Webpack Bundle Analyzer is started at http://127.0.0.1:8888

5、根据package.json做覆盖覆盖安装时,检查

npm i
 
> core-js@3.6.5 postinstall L:\Vue3Test\MyVue3Proj1\my-site\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

总结

加载全部内容

相关教程
猜你喜欢
用户评论