I have an electron app that is written in typescript. Here is the minimum code:
someModule.ts:
function someFunction() {}
export default someFunction;
main.ts:
import someFunction from "./someModule";
someFunction();
index.html:
...
<script defer src="main.js"></script>
...
index.ts (package entry which starts with npm start):
import { BrowserWindow, app } from "electron";
const createWindow = () => {
const win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
});
win.loadFile("./index.html");
}
app.whenReady().then(() => {
createWindow();
});
app.on("window-all-closed", () => {
if(process.platform !== "darwin") app.quit();
})
tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"lib": ["DOM"],
"module": "CommonJS",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
When I run the app (by npx tsc && node index.js command (which is npm start in package scripts)) the console in electron window gives an error:
Uncaught ReferenceError: exports is not defined
at main.js:5:23
How can I fix this?
"module": "commonjs"and I don't have"type": "module"in package.json. But the error occurs. @JaredSmith @AlainBUFERNE