如何告诉打字稿编译器不使用导出?

问题描述

我对编译的打字稿代码有问题。 我正在使用 package.json 中需要 "type": "module" 选项的外部包,否则会引发错误。 由于需要此选项,因此我以这种方式编辑了我的 tsconfig

    {
    "compilerOptions": {
                        
      "target": "es2015","module": "ES2020","lib": ["DOM","ES2017","es5"],"outDir": "./build","removeComments": true,"moduleResolution": "node","baseUrl": "./src","resolveJsonModule": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true       
    },"include": [
      "src/**/*"
    ]
}

但是编译后的代码告诉我没有定义导出

exports.__esModule = true;
ReferenceError: exports is not defined

我已经尝试过:

  • 导入 es5 作为库
  • 将 tsconfig 模块更改为 es2015、commonjs(废话,但我尝试过)
  • 将 tsconfig 目标更改为 es2017、es2015、ES2020
  • 安装模块 common-js

这一切都不起作用

解决方法

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

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

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