标签搜索

目 录CONTENT

文章目录

Node和npm升级之后出现版本不兼容导致程序异常的问题

沙漠渔
2024-02-04 14:46:34 / 0 评论 / 0 点赞 / 1,218 阅读 / 3,453 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2024-02-04,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

今天build的时候提示有一个重要更新,请更新npm,然后就手欠的情况下给点了,然后就不出意外的出意外了。

升级前的提示信息

npm升级提示信息.png
乍一看,红字变绿字,还显得那么的无害,然后就按照提示进行升级了。

升级NPM

>npm install -g npm
 -> xxx\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
 -> xxx\Roaming\npm\node_modules\npm\bin\npx-cli.js
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":"^18.17.0 || >=20.5.0"} (current: {"node":"14.17.6","npm":"6.14.15"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]

+ [email protected]
added 218 packages from 102 contributors in 26.091s

升级过程和升级结果也显得这么平淡无奇,只是提示了两个warn信息,版本node版本需要是18.17或者大于20.5,当前是14.17.6

然后跑一把build,然后就

ERROR: npm v10.4.0 is known not to run on Node.js v14.17.6.  This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

ERROR的大字就甩到脸上了。

尝试退回NPM版本

想着既然是升级npm由6.14.15升级到10.4.0导致的问题,那就回退一下版本总可以了吧。

>npm install -g [email protected]

现实总是这么得冷酷无情,回退版本失败。

ERROR: npm v10.4.0 is known not to run on Node.js v14.17.6.  This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

一样的配方,一样的提示信息,那咋办额?然后错误信息提示Nodejs版本问题,要不再尝试升级一下Nodejs试试(瑟瑟发抖)

升级Nodejs

此处按下不表,我是直接通过软件应用商城升级安装的,当然你可以尝试直接官网下载之后进行升级。

Tips:这里我忽略了一个问题,软件应用商城搜索Node的时候,最新版本为2023年2月份发布的,软件版本为18.14.2,升级时没怎么关注到,当然可能升级之后还是不能build的原因有可能就是这个问题导致的,但是who care,我只是想能保证程序可以正常编译,别把环境搞乱了就好。

跑一把build

不出意外的还是出了意外,重新build还是报错。

|  Building for production...Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    ...
|  Building for production...Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
\  Building for production..loader-runner\lib\LoaderRunner.js:114
                        throw e;

当然他这里还提示我一个信息,当时处理过程中并没咋关注我更新的node版本是18.14.2

Node.js v18.14.2

是不符合提示信息中的18.17.0的,所以这里可能也是我的锅。

回退Npm

npm install -g [email protected]

提示信息如下

npm WARN cli npm v10.4.0 does not support Node.js v18.14.2. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

removed 91 packages, and changed 110 packages in 36s

3 packages are looking for funding
  run `npm fund` for details

查一下版本npm -v 已经回退到6.14.15

再跑一把build

想着到目前为止,已经将npm回退到最初的起点,试试能不能进行build了呗。无情总是把我打哭

Node.js v18.14.2
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

回退Nodejs

实在没辙了,那就不过是从头再来,然后重新安装Nodejs的14.17.6版本,还好电脑上还有之前的备份,直接安装呗,然后又提示我已安装了更新版本,将会直接关闭窗口~~~

我去,还可以这样!

然后设置-应用-卸载!!!

你狠,我更狠!

重新安装Nodejs的14.17.6版本,一切都看起来顺利了起来。

再次跑一把build

哎呦我去,终于回到了最初的起点,呆呆地站在镜子前,我到底做了什么?手欠该收拾了啊!
终于恢复了原来的环境,然后也可以正常build了。

重要提示
尽量不要手欠,因为这搞过很多版本不兼容的事了,唉 之前就已经遇到过Jenkins升级插件出现版本不兼容问题,然后Jenkins启动失败,导致界面进去之后所有的任务都看不到了,当时吓得魂都快跑了,然后也是这么一步一步的捣腾好的,白白增加了很大的工作量,不过话又说回来,不捣鼓捣鼓这捣鼓捣鼓拿,也不会知道这些东西,Jenkins的那篇文章看着浏览量已经上千,相信已经帮助了不少人了。

0
广告 广告

评论区