美文网首页
ts-node 编译 .ts 文件,报错ERR_UNKNOWN_

ts-node 编译 .ts 文件,报错ERR_UNKNOWN_

作者: easy_luo | 来源:发表于2025-01-08 20:45 被阅读0次
[Running] ts-node "/Users/easy/Documents/Harmony/Project/Hello.ts"
TypeError: Unknown file extension ".ts" for /Users/easy/Documents/Harmony/Project/Hello.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:218:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:244:36)
    at defaultLoad (node:internal/modules/esm/load:122:22)
    at async ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:479:32)
    at async ModuleJob._link (node:internal/modules/esm/module_job:112:19) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

在当前目录新增配置文件 tsconfig.json 解决

企业微信截图_37f0537d-bef1-4079-9964-0234d1771092.png
{
  "ts-node": {
    "compilerOptions": {
      "module": "CommonJS" 
    }
  }
}

相关文章

网友评论

      本文标题:ts-node 编译 .ts 文件,报错ERR_UNKNOWN_

      本文链接:https://www.haomeiwen.com/subject/udxeyjtx.html