微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决为什么`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 举报,一经查实,本站将立刻删除。