目录
- 前言
- 异常现象
- 解决方案
- 总结
前言
之前使用软件管家升级了Nodejs,今天在运行Vue项目的时候老是报错,查了很多资料,最后确定是Nodejs版本过高导致的。
异常现象
E:\project\ry\RuoYi-Cloud\ruoyi-ui>npm run dev> ruoyi@3.6.4 dev
> vue-cli-service serveINFO Starting development server...
10% building 2/5 modules 3 active ....js!E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\@vue\cli-plugin-eslint\node_modules\eslint-loader\index.js??ref--13-0!E:\project\ry\RuoYi-Cloud\ruoyi-ui\src\main.jsE
rror: error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:71:19)at Object.createHash (node:crypto:133:10)at module.exports (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)at NormalModule._initBuildHash (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)at handleParseError (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3at iterateNormalLoaders (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)at iterateNormalLoaders (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:221:10)at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:236:3at runSyncOrAsync (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:130:11)at iterateNormalLoaders (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:232:2)at Array.<anonymous> (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)at Storage.finished (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
node:internal/crypto/hash:71this[kHandle] = new _Hash(algorithm, xofLen);^Error: error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:71:19)at Object.createHash (node:crypto:133:10)at module.exports (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)at NormalModule._initBuildHash (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)at handleParseError (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3at iterateNormalLoaders (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)at Array.<anonymous> (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)at Storage.finished (E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9at E:\project\ry\RuoYi-Cloud\ruoyi-ui\node_modules\graceful-fs\graceful-fs.js:123:16at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],library: 'digital envelope routines',reason: 'unsupported',code: 'ERR_OSSL_EVP_UNSUPPORTED'
}Node.js v18.14.2
error:0308010C:digital envelope routines::unsupported
主要是因为 nodeJs V17 版本发布了 OpenSSL3.0 对算法和秘钥大小增加了更为严格的限制,nodeJs v17 之前版本没影响,但 V17 和之后版本会出现这个错误。 我的node版本是v18+
由于nodejs版本过高,导致vue-cli项目运行报错
解决方案
解决方案1:修改package.json配置文件
修改前
修改后
修改的内容
"dev": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --open",
"build:prod": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build --report",
"build:stage": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build --mode staging",
"preview": "set NODE_OPTIONS=--openssl-legacy-provider && node build/index.js --preview",
解决方案2:每次启动项目前,输入配置命令
set NODE_OPTIONS=--openssl-legacy-provider
总结
到此这篇关于nodejs版本过高导致vue-cli项目无法正常运行的两种解决方案就介绍到这了,希望本文能对大家有所帮助。