The Vue project reports an error when running: error:0308010C:digital envelope routines::unsupported

When running the Vue project using Node.js version 18.16.0, the following error message appears:

This is because in the Node 18 version, OpenSSL 3.0 and above are used by default. This version is different from the previous version. It adds some new features, but also removes some old features, resulting in Some code that relies on older versions will not run properly. Therefore, in some applications that use the Old Crypto API or other different APIs related to OpenSSL, strange problems may occur, such as errors in calculating DB hash values, HTTP request timeouts or connection unexpected closures, etc. In this case, we can force the use of older versions of the Crypto API by setting the NODE_OPTIONS environment variable.

Add set NODE_OPTIONS=--openssl-legacy-provider in the package.json file as follows:

"scripts": {
    "dev": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
  },

This problem will also occur when using npm run build to package the project. The same solution is to modify the package.json file:

"scripts": {
    "build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
  },

Guess you like

Origin blog.csdn.net/lq313131/article/details/130543910