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?
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.
Comments