typescript 使用ts-node运行.mts

lf3rwulv  于 2023-03-24  发布在  TypeScript
关注(0)|答案(1)|浏览(260)

有没有一种方法可以使用ts-node来运行.mts文件。我试过这样做,但在导入时出现错误(从.mts文件中)。

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

我不想这样做,因为我不确定它将如何影响更广泛的回购。

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

我可以接受.mjs,但我希望一切都是TS。
编辑:
https://github.com/TypeStrong/ts-node/issues/1007
ts-node execute typescript with module import and module defined

lskq00tm

lskq00tm1#

try ts-node --esm index.mts如果出现错误,您可能需要配置另一个tsconfig.js,请参阅How can I generate a tsconfig.json file?
您可以在命令行中使用--project参数指定备用tsconfig,例如:
ts-node --project ./other-tsconfig.json --esm index.mts

相关问题