"Unexpected token ." when using optional chaning "?." syntax when running mocha

Igor K.

I'm playing around with TS and encountered an error when trying to run a test for my code. I have a the following piece of code:

return this._map.get(y)?.get(x)

When I run the code for browser, everything works fine. When I run a test using mocha, however, it throws an error :

        return this._map.get(y)?.get(x);        
                                ^

SyntaxError: Unexpected token .

From what I managed to read, I'm supposed to configure tsc differently for NodeJS environment for things to work, but I was under the impression it was more about module resolution than syntax. Could it be that I need to upgrade to any specific NodeJS version? I've tried Node 10 through 13 but none worked. What am I missing?

T.J. Crowder

Optional chaining is still behind a flag in Node.js v13. It isn't anymore in the latest Node.js (v14.9.0), though it still was in v14.4.0, so it got deflagged somewhere between those two.

Either update to the latest, or to enable it in v13 and earlier versions of v14:

node --harmony-optional-chaining ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

unexpected token import when using Mocha with Babel

From

Babel unexpected token import when running mocha tests

From Dev

syntax error near unexpected token `(' when running program in cygwin

From Dev

Getting unexpected token when running

From Dev

syntax error near unexpected token `>' when using '&>>' redirection operator

From Dev

-bash: syntax error near unexpected token `(' when using lookahead and lookback?

From Dev

Unexpected token when using map

From Dev

Syntax error near unexpected token `(' when running shell script from XAMPP

From Dev

Unexpected Token @ when using babel decorator

From Dev

React "return" unexpected token when using babelify

From Dev

Jquery unexpected token when using a function

From Dev

Uncaught SyntaxError: Unexpected token . when using ClassNotty

From Dev

Unexpected token "." when using .bind() in JavaScript

From Dev

Unexpected token "indent" when using Pug templates

From Dev

Unexpected token < when using reactjs app

From Dev

Parsing error: Unexpected token .. when using eslint

From Dev

Unexpected token error when using ionic/cordova

From Dev

"Unexpected Token" when using the map function in React

From Dev

Unexpected token error when using PHP with JavaScript

From Dev

Bash: Syntax Error Near Unexpected Token `(' When Using Wgrib2

From Dev

Why when using parenthesis with the egrep command in terminal I get the error: -bash: syntax error near unexpected token?

From Dev

Test Script is running in Postman but got unexpected token '<' at 1:1 when ran in Azure pipeline using Newman

From Dev

"SyntaxError: Invalid or unexpected token" when running node-red using PM2 on Win ES 7

From Dev

Syntax Error: Token ':' is an unexpected token when passing variable to directive

From Dev

Getting "Syntax Error: Unexpected Token" when calling a function from ajax

From Java

syntax error near unexpected token '(' in bash script when selecting files

From Java

syntax error near unexpected token `do' when run with sudo

From Dev

Syntax error near unexpected token "(" when declaring arrays in bash

From Dev

Syntax error: Unexpected token ) when building Docusaurus on Node 6

Related Related

  1. 1

    unexpected token import when using Mocha with Babel

  2. 2

    Babel unexpected token import when running mocha tests

  3. 3

    syntax error near unexpected token `(' when running program in cygwin

  4. 4

    Getting unexpected token when running

  5. 5

    syntax error near unexpected token `>' when using '&>>' redirection operator

  6. 6

    -bash: syntax error near unexpected token `(' when using lookahead and lookback?

  7. 7

    Unexpected token when using map

  8. 8

    Syntax error near unexpected token `(' when running shell script from XAMPP

  9. 9

    Unexpected Token @ when using babel decorator

  10. 10

    React "return" unexpected token when using babelify

  11. 11

    Jquery unexpected token when using a function

  12. 12

    Uncaught SyntaxError: Unexpected token . when using ClassNotty

  13. 13

    Unexpected token "." when using .bind() in JavaScript

  14. 14

    Unexpected token "indent" when using Pug templates

  15. 15

    Unexpected token < when using reactjs app

  16. 16

    Parsing error: Unexpected token .. when using eslint

  17. 17

    Unexpected token error when using ionic/cordova

  18. 18

    "Unexpected Token" when using the map function in React

  19. 19

    Unexpected token error when using PHP with JavaScript

  20. 20

    Bash: Syntax Error Near Unexpected Token `(' When Using Wgrib2

  21. 21

    Why when using parenthesis with the egrep command in terminal I get the error: -bash: syntax error near unexpected token?

  22. 22

    Test Script is running in Postman but got unexpected token '<' at 1:1 when ran in Azure pipeline using Newman

  23. 23

    "SyntaxError: Invalid or unexpected token" when running node-red using PM2 on Win ES 7

  24. 24

    Syntax Error: Token ':' is an unexpected token when passing variable to directive

  25. 25

    Getting "Syntax Error: Unexpected Token" when calling a function from ajax

  26. 26

    syntax error near unexpected token '(' in bash script when selecting files

  27. 27

    syntax error near unexpected token `do' when run with sudo

  28. 28

    Syntax error near unexpected token "(" when declaring arrays in bash

  29. 29

    Syntax error: Unexpected token ) when building Docusaurus on Node 6

HotTag

Archive