I get the following error when executing yarn -dev
, yarn serve
or npm run dev
:
node:internal/crypto/hash:67
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
This error usually means that the version of OpenSSL is not compatible with your version of Node.js. Even though you have tried downgrading your Node.js version to 14.x, the problem persists. After searching various sources and trying various methods, you finally found a solution.
The solution is to modify package.json
the file to add the following before the relevant build command:
For macOS systems:
"scripts": {
"serve": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve"
},
For Windows systems:
"scripts": {
"serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve"
},
By adding the above code, you set NODE_OPTIONS
the environment variable for the build command, using --openssl-legacy-provider
the option to resolve incompatibilities with OpenSSL versions. In this way, this environment variable setting will be automatically applied when the relevant build command is executed.
Whether it's project iteration or team development, with this method, you can solve the problem of OpenSSL version compatibility and ensure that related build commands can be executed smoothly.