As in the title, the react project is created based on vite, and an error is reported when writing the ?. operator. There is another project but it works fine. Comparing the package.json and vite.config.js of the two projects, some dependencies have been updated, but they are still unresolved.
Current dependency version:
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
……
"@vitejs/plugin-react": "^3.0.1",
"vite": "^4.0.4"
After checking on the Internet, a new babel.config.js is created in the root directory, and the content is
module.exports = {
plugins: ["@babel/plugin-proposal-optional-chaining"]
}
And install dependencies:
yarn add @babel/plugin-proposal-optional-chaining
Just restart the project.
But I don't know why another project doesn't need this operation.