1

I created a new project with the create-react-app scaffold, and then I wanted to use the optional-chaining plug-in of babel. I installed the package according to the document and configured it, but vscode prompted grammatical errors. What can help me? please.

  1. this is my package.json.
  2. this is the problem: enter image description here
quicklikerabbit
  • 3,257
  • 6
  • 26
  • 39
SagaciousLit
  • 11
  • 1
  • 2

2 Answers2

1

If you are using CRA there is probably no way instead of ejecting project and applying Babel presets manually (according to https://github.com/facebook/create-react-app/issues/4604).

However, if you are decided to use eject there should be able to add plugin to babel config which is described here https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining. Probably applying stage-0 preset of Babel (https://babeljs.io/docs/en/babel-preset-stage-0) can also be a solution.

Edit: see also Null-safe property access (and conditional assignment) in ES6/2015

Wwarrior
  • 11
  • 3
1

The error you are seeing is from Visual Studio Code's built-in JavaScript and/or TypeScript validator. In order to circumvent this, add this to your vscode settings.json file:

"javascript.validate.enable": false

Additionally you can disable the built-in TypeScript validator like this:

"typescript.validate.enable": false

Once those are disabled, eslint will take over and show you the proper errors when applicable.

james
  • 5,006
  • 8
  • 39
  • 64