Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-node not working with TypeScript 3.7 features #909

Closed
andrew-kapustin opened this issue Nov 13, 2019 · 2 comments
Closed

ts-node not working with TypeScript 3.7 features #909

andrew-kapustin opened this issue Nov 13, 2019 · 2 comments
Labels

Comments

@andrew-kapustin
Copy link

An errors occurs when using optional chaining or nullish coalescing features
My code:

export default async function main() {
  const test: any = {};
  return test.qwe ?? 'test result';
}

My mocha test:

describe('Main', () => {
  it('should return test result', (done) => {
    main()
      .then((result) => {
        result.should.be.equal('test result');
        done();
      })
      .catch(done);
  });
});

Stacktrace:

$ 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.<anonymous> (/home/kapustin-aa/test-ts-3.7/test/index.ts:4:1)
    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 (<anonymous>)
    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.<anonymous> (/home/kapustin-aa/test-ts-3.7/node_modules/mocha/bin/mocha:164:29)
    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.
@blakeembrey
Copy link
Member

Please search issues before creating another. Duplicate of #906 and also not a TypeScript Node issue.

@cmosgh
Copy link

cmosgh commented Sep 30, 2020

If someone get to this the problem is in tsconfig , namely you've chosen "target":"esnext" it should be "es2020" or "es2019"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants