1. Install @babel/ plugin-proposal-option-chaining

// Install dependencies# npm install @babel/plugin-proposal-optional-chaining -S 
Copy the code

2. Configure the Babel. Config. Js

Babel in priority

// Add "@babel/plugin-proposal-optional-chaining" to plugins in babel.config.js
module.exports = { 
    plugins: [ '@babel/plugin-proposal-optional-chaining' ] // Optional chain? .
}
Copy the code

If already can run successfully, did not need to continue to look down, if still report the error below, then continue!


Upgrade @vue/ CLI-plugin-babel and core-js

# NPM install @vue/[email protected] -d
# NPM install [email protected] -s
Copy the code

4. Delete the babel-Polyfill configuration

Because Babel-Polyfill has not been updated for 4 years and has been replaced by Core-JS

// The directory is vue.config.js
config.entry = ["babel-polyfill"."./src/main.js"];
/ / to = = = >
config.entry = ["./src/main.js"];
Copy the code

Finally, we’re done

Note: The latest Babel already supports optional chain operations, so the first and second steps can be omitted. Ha ha!