ts-node 在 cli 中的 repl 或 eval 中无法使用动态导入或 import 语句

Ric*_*lva 8 node.js typescript ts-node

我一直在尝试运行 eval 或从 repl 导入 esm 模块,但无法使其工作。我尝试了一些在互联网上找到的东西。例如:是否可以将 Typescript 导入到正在运行的 ts-node REPL 实例中?

不确定我错过了什么,我收到的错误是:

  1. 来自带有动态导入的 REPL:
var a = await import("./test").then(x=>x)
//or
var a = await import("./test").then(x=>x)
//gives
//TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
Run Code Online (Sandbox Code Playgroud)
  1. 在 REPL 上使用 import 语句
import * as test from './src/test';
//works but then when I try to use 'test' it gives
//SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
Run Code Online (Sandbox Code Playgroud)
  1. 在 cli 上使用
ts-node --esm -e  "import * as z from './src/test'; console.log(z); export {}"
//gives
//Cannot use import statement outside a module
Run Code Online (Sandbox Code Playgroud)
ts-node --esm -e "const z= import('./src/test').then(console.log);"
//gives
//TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

我正在使用全局安装在节点 18.2.0 中的 ts-node 10.9.1