An errors occurs when using optional chaining or nullish coalescing features
My code:
```(javascript)
export default async function main() {
const test: any = {};
return test.qwe ?? 'test result';
}
My mocha test:
```(javascript)
describe('Main', () => {
it('should return test result', (done) => {
main()
.then((result) => {
result.should.be.equal('test result');
done();
})
.catch(done);
});
});
Stacktrace:
```(bash)
$ yarn test
yarn run v1.13.0
$ yarn build && mocha
$ tsc
/home/kapustin-aa/test-ts-3.7/src/index.ts:5
return test.qwe ?? 'hello world';
^
SyntaxError: Unexpected token ?
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Module.m._compile (/home/kapustin-aa/test-ts-3.7/node_modules/ts-node/src/index.ts:530:23)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.require.extensions.(anonymous function) [as .ts] (/home/kapustin-aa/test-ts-3.7/node_modules/ts-node/src/index.ts:533:12)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module.m._compile (/home/kapustin-aa/test-ts-3.7/node_modules/ts-node/src/index.ts:530:23)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.require.extensions.(anonymous function) [as .ts] (/home/kapustin-aa/test-ts-3.7/node_modules/ts-node/src/index.ts:533:12)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at /home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/mocha.js:334:36
at Array.forEach (
at Mocha.loadFiles (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/mocha.js:331:14)
at Mocha.run (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/mocha.js:809:10)
at Object.exports.singleRun (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/cli/run-helpers.js:108:16)
at exports.runMocha (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/cli/run-helpers.js:142:13)
at Object.exports.handler.argv [as handler] (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/cli/run.js:292:3)
at Object.runCommand (/home/kapustin-aa/test-ts-3.7/node_modules/yargs/lib/command.js:242:26)
at Object.parseArgs [as _parseArgs] (/home/kapustin-aa/test-ts-3.7/node_modules/yargs/yargs.js:1087:28)
at Object.parse (/home/kapustin-aa/test-ts-3.7/node_modules/yargs/yargs.js:566:25)
at Object.exports.main (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/lib/cli/cli.js:68:6)
at Object.
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```
Please search issues before creating another. Duplicate of https://github.com/TypeStrong/ts-node/issues/906 and also not a TypeScript Node issue.
If someone get to this the problem is in tsconfig , namely you've chosen "target":"esnext" it should be "es2020" or "es2019"