skip to Main Content

I got this error when I used question mark after variable in react js

Module parse failed: Unexpected token (25:28) You may need an
appropriate loader to handle this file type.

|   console.log(cryptos);
|   useEffect(function () {
>     var filteredData = data?.data.coins.filter(function (item) {
|       return item.name.toLowerCase().includes(searchTerm);      
|     });

Anyone faced this error before?

2

Answers


  1. ?. is an operator named as optional chain operator. It is new in es11. May be it’s not updated in react.js , that’s why you are getting error

    Login or Signup to reply.
  2. Just check your NodeJS version with the following command.

    node --version
    

    As mentioned in the browser compatibility in the Optional chaining documentation, the NodeJS version should be at least 14.0.0.

    If your NodeJS version is lower than it, you should upgrade it to use these latest features.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search