Solving the problem of Error: error:0308010C:digital envelope routines::unsupported when running an old version of the project

environment

Node.js :v18.12.1

Development tools: VsCode

The error when running the project is as follows:

//报错主要提示,第一行。
Error: error:0308010C:digital envelope routines::unsupported  
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at BulkUpdateDecorator.hashFactory (D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\util\createHash.js:145:18)
    at BulkUpdateDecorator.update (D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\util\createHash.js:46:50)    at OriginalSource.updateHash (D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\node_modules\webpack-sources\lib\OriginalSource.js:131:8)
    at NormalModule._initBuildHash (D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\NormalModule.js:888:17) 
    at handleParseResult (D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\NormalModule.js:954:10)
    at D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\NormalModule.js:1048:4
    at processResult (D:\editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\NormalModule.js:763:11)
    at D:editingPro\isc-web-dev-jiangsu\node_modules\webpack\lib\NormalModule.js:827:5 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',

Node.js v18.12.1   //当前版本号。

reason

The version of Node.js is too high. OpenSSl3.0 released in the Node.js V17 version adds strict restrictions on allowed algorithms and key sizes, which may have an impact on the ecosystem.

node -v    //cmd进入命令行输入命令,查看自己的版本号

Solution:

Permanent solution to the problem:

First: command line input

$env:NODE_OPTIONS="--openssl-legacy-provider"

Second: Take the initiative to lower the version of Node.js.

Modify node.js to a version no higher than 16

This method is not recommended because in actual development, it is unreasonable to require every developer to downgrade the version because of one project. Some developers have multiple projects, which will cause a chain reaction. No details will be introduced here.

Use environment variables to solve the problem temporarily : (Command line input must be in administrator mode)

First: Do not enter in the terminal of the development tool in the windows environment!

Enter on the command line: Restart the project after completing the input

set NODE_OPTIONS=--openssl-legacy-provider 

Second: Do not enter in the terminal of the development tool in Linux or WSL environment!

export NODE_OPTIONS=--openssl-legacy-provider

Guess you like

Origin blog.csdn.net/youyudehan/article/details/128476816