Typescript会在编译期间删除我的模块之一,因为不存在导出常量

所以我有一些Firebase函数分布在多个文件中:

  • index.ts(导入和导出所有其他文件)
  • functions1.ts
  • functions2.ts

index.ts的内容:

export * from './functions1';
export * from './functions2';

两个文件中的功能看起来都像这样:

exports[FireFunctions.exampleFunction] = functions.https.onCall(async (data,context) => {
    if (!context.auth) {
        return null;
    }


    // ...
});

但是在functions1.ts中,有两个函数可以这样导出:

export const test = functions.https.onCall(async (data,context) => {

    // ...

});*/

构建文件时,在index.js中输出总是像这样:

exports.__esModule = true;
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./functions1"),exports);

我知道会发生这种情况,因为在functions2.ts文件中没有export const,因为我已经对其进行了测试。

但是我不想通过export const方法导出任何内容,因为我需要基于字符串名称FireFunctions.exampleFunction2导出它。

您知道如何强制将其保存在生成​​的文件中吗?

这是我的tsconfig:

{
  "compilerOptions": {
    "baseUrl": "./","module": "commonjs",//"moduleResolution": "node","noImplicitReturns": true,"noImplicitAny": false,"noUnusedLocals": false,"rootDir": "src","outDir": "lib","sourceMap": true,"strict": false,"importHelpers": true
  }
}
mengdegong 回答:Typescript会在编译期间删除我的模块之一,因为不存在导出常量

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3141417.html

大家都在问