When Nodejs runs the vue project, an error is reported: Error: error:0308010C:digital envelope routines::unsupported

foreword

When the front-end project uses ( npm run dev ) to run the vue project, an error occurs: Error: error:0308010C:digital envelope routines::unsupported

After exploration, I found the problem, mainly because the nodeJs V17 version released OpenSSL3.0, which added stricter restrictions on the algorithm and key size, which caused the version before nodeJs V17 to not be affected by the shadow, but nodeJs V17 and later versions will appear this error.

That is, the npm upgrade caused the initialization failure caused by the incompatibility with OpenSSL, that is, the nodeJs version was too high and the operation failed.

The nodeJs version installed in the system happens to be V18, so this error system appears.

solution

1. Change the system environment variables to solve

2. Change the project environment variables to solve

3. Replace the NodeJs version to solve

specific demonstration

1. Change system environment variables

① Windows platform

Right click on my computer → properties → advanced system settings → add system variable: NODE_OPTIONS = --openssl-legacy-provider

 

 

②Linux/Mac platform

export NODE_OPTIONS=--openssl-legacy-provider

After completion, it is recommended to reopen a command line window to start the service.

2. Change the project environment variables to solve

① Add in the scripts of package.json: SET NODE_OPTIONS=--openssl-legacy-provider

Code before adding:

  "scripts": {
    "dev": "vue-cli-service serve",
    "build:prod": "vue-cli-service build",
    "build:stage": "vue-cli-service build --mode staging",
    "preview": "node build/index.js --preview",
    "lint": "eslint --ext .js,.vue src",
    "test:unit": "jest --clearCache && vue-cli-service test:unit",
    "test:ci": "npm run lint && npm run test:unit",
    "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml"
  },

Code after adding:

  "scripts": {
    "dev": "set NODE_OPTIONS=--openssl-legacy-provider & vue-cli-service serve",
    "build:prod": "vue-cli-service build",
    "build:stage": "vue-cli-service build --mode staging",
    "preview": "node build/index.js --preview",
    "lint": "eslint --ext .js,.vue src",
    "test:unit": "jest --clearCache && vue-cli-service test:unit",
    "test:ci": "npm run lint && npm run test:unit",
    "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml"
  },

It should be noted here that if the version of nodejs in the team is inconsistent, do not submit the package.json file.

②Similar to ①, in the editor integrated terminal, directly set the environment variable for control (this method can only be temporarily solved)

details as follows:

Right click on the package.json file, open it in the integrated terminal, directly enter set NODE_OPTIONS=--openssl-legacy-provider and press Enter, then run npm run serve to run the project again.

// windows系统
set NODE_OPTIONS=--openssl-legacy-provider

// linux系统
export NODE_OPTIONS=--openssl-legacy-provider

3. Replace the NodeJs version to solve

Uninstall the local NodeJs environment and switch to versions prior to NodeJsV17.

Guess you like

Origin blog.csdn.net/loveliqi/article/details/129356075
Recommended