【发布时间】:2023-01-12 08:02:51
【问题描述】:
我第一次尝试制作一个简单的应用程序,但是每当我尝试导入任何 npm 包时,我都会收到此错误。我不确定我做错了什么,因为我使用的是 npm 包 electron-reload 并且没有抛出任何错误。
ERROR:
require() of ES Module
这是我的tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "CommonJS",
"outDir": "./app/js/",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
},
"exclude": ["./app/js/**/*.js"],
"compileOnSave": true
}
这是引发错误的代码:
import Hwid from "hwid";
ipcMain.on("get-hwid", (event) => {
console.log(Hwid());
});
最后,这是我的BroswerWindow代码:
const window = new BrowserWindow({
width: 700,
frame: false,
height: 700,
resizable: false,
transparent: true,
roundedCorners: true,
icon: path.join(__dirname, "../design/imgs/dully_logo.png"),
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
preload: path.join(__dirname, "preload.js"),
devTools: false,
},
});
window.loadFile(path.join(__dirname, "../design/index.html"));
我正在使用 TypeScript,因为我比普通 JS 更喜欢它,我只是想知道该怎么做或为什么这个错误会停止我的开发。我希望程序包能正常运行,但没有任何效果。
【问题讨论】:
标签: javascript typescript electron