为什么`tsc` 不能正确导入文件?

问题描述

我正在使用 TypeScripttsc。 我按如下方式构建我的应用程序:

$ tsc --project tsconfig.json

我按如下方式开始我的脚本:

node dist/out-tsc/main.js

并收到以下异常:

internal/process/esm_loader.js:74
    internalBinding('errors').triggeruncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'dist/out-tsc/src/io'
    imported from dist/out-tsc/main.js

AFAICS 一些其他线程建议执行导入,如 `import { foo } import "./test.js"``` 但这当然不起作用,因为我的“开发构建”没有任何 JS 文件.谁能帮我澄清一下这里发生了什么?

tsconfig.json

{
    "compileOnSave": false,"compilerOptions": {
      "baseUrl": "./","outDir": "./dist/out-tsc","sourceMap": true,"declaration": false,"downlevelIteration": true,"experimentalDecorators": true,"moduleResolution": "node","importHelpers": true,"target": "es2015","allowSyntheticDefaultImports": true,"typeRoots": [
        "node_modules/@types","./src/typings.d.ts" // typings for plain json files
      ],"lib": [
        "esnext","es2019","es2017","es2016","es2015","dom"
      ]
    },"include": [
      "main.ts","src/**/*.ts"
    ],"exclude": [
      "node_modules"
    ]
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)