1

Is there a way to use ts-node to run .mts files. I've tried to do so but am getting errors on imports (from within the .mts file).

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

I don't want to do this because I'm not confident how it will impact the broader repo.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

I can live with an .mjs but I'd like everything to be TS.

Edit:

https://github.com/TypeStrong/ts-node/issues/1007

ts-node execute typescript with module import and module defined

dras
  • 138
  • 4
  • 14

1 Answers1

0

try ts-node --esm index.mts If that gives you errors, you may have to configure an alternate tsconfig.js, see How can I generate a tsconfig.json file?

You can specify an alternate tsconfig on the command line with the --project argument, e.g.

ts-node --project ./other-tsconfig.json --esm index.mts

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".mts" for /Users/me/WebstormProjects/drive-test/src/accessTokens.mts – Nikos May 15 '23 at 18:48