【发布时间】:2022-12-17 01:43:17
【问题描述】:
我正在做一个电子反应打字稿应用程序。
我想预加载一个数据库 (sqlite) 函数调用,以便我可以在渲染器 (react) 环境中使用该方法。
为此,我在另一个名为testmgr.ts 的文件中准备了函数
const dbmgr = require('./dbmgr'); //dbmgr is the file that prepares the database (its file on the pc)
const dbTest = dbmgr.db;
function getSomeNames() {
const query = 'SELECT * FROM test';
const stmt = dbTest.prepare(query);
const res = stmt.all();
return res;
}
export {};
现在在 preload.ts 文件中,我有这个:
const testMgr = require("./testmgr.ts");
const { contextBridge } = require("electron");
const getNames = () => {
return testMgr.getSomeNames();
};
contextBridge.exposeInMainWorld("api", { getNames: getNames });`
编译时,我在控制台中收到以下错误:
语法错误:意外的令牌“导出”
如果我从文件
testmgr.ts中删除export {},我将收到此错误testmgr.ts' 不能在 '--isolatedModules' 下编译,因为它被认为是全局脚本文件。添加导入、导出或空的“export {}”语句以使其成为模块。
我需要做什么才能避免这个问题?
【问题讨论】:
-
你有没有找到解决这个问题的方法?
标签: node.js typescript module electron export