chore(build): switch main+preload to CJS for Electron 41 module hook
Two related runtime defects surfaced when first attempting
`npm run build` + Electron launch:
1. Renderer html files referenced `/src/.../main.tsx`, which
vite dev resolves but vite production rollup cannot. Changed
both inbox and quickcapture to `./main.tsx` (sibling-relative).
2. Electron 41's main-process module hook only injects the
real `electron` API into `require('electron')` calls inside
CommonJS modules. With package.json `"type": "module"` set,
electron-vite emitted ESM bundles that did
`import { app } from "electron"`; Node's ESM CJS-interop
then loaded the on-disk index.js (which exports the binary
path string) instead, leaving `app` undefined at startup.
Fix: drop `"type": "module"` so electron-vite emits CJS for
main + preload (renderer is unaffected — vite handles its own
ESM transform regardless). Source files keep modern import
syntax via the default-import + destructure pattern
(`import electron from 'electron'; const { app } = electron;`)
which transpiles correctly to `const { app } = require('electron')`
in the CJS output.
Also updated `electron-log/main` -> `electron-log/main.js`
because Node ESM strict resolution requires the `.js` extension
even though the package's CJS entry serves both.
Verification: `npm run build` produces 47-module renderer +
1005KB main bundle without errors. `npm run typecheck` clean.
Unit suite (52 tests) unaffected.
Plan deviation log: Task 4 (logger), Task 30 (main wiring), and
Tasks 17/18/22/30 referencing electron imports landed with named
imports per plan; this commit refactors them to default+destructure
without changing semantics.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
"name": "inkling",
|
||||
"version": "0.2.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "out/main/index.js",
|
||||
"scripts": {
|
||||
"dev": "electron-vite dev",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { app, BrowserWindow, Notification } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { app, BrowserWindow, Notification } = electron;
|
||||
import '@shared/types';
|
||||
import { initLogger, logger } from './logger.js';
|
||||
import { resolveProfilePaths } from './paths.js';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import electron from 'electron';
|
||||
import type { CaptureService } from '../services/CaptureService.js';
|
||||
import type { BrowserWindow } from 'electron';
|
||||
const { ipcMain } = electron;
|
||||
|
||||
export function registerCaptureApi(
|
||||
captureService: CaptureService,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ipcMain, BrowserWindow } from 'electron';
|
||||
import electron from 'electron';
|
||||
import type { BrowserWindow } from 'electron';
|
||||
const { ipcMain } = electron;
|
||||
import type { NoteRepository } from '../repository/NoteRepository.js';
|
||||
import type { ContinuityService } from '../services/ContinuityService.js';
|
||||
import type { CaptureService } from '../services/CaptureService.js';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import log from 'electron-log/main';
|
||||
import { app } from 'electron';
|
||||
import log from 'electron-log/main.js';
|
||||
import electron from 'electron';
|
||||
const { app } = electron;
|
||||
import { join } from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { app } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { app } = electron;
|
||||
import { join } from 'node:path';
|
||||
import { mkdirSync } from 'node:fs';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { globalShortcut } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { globalShortcut } = electron;
|
||||
|
||||
export interface HotkeyBinding {
|
||||
accelerator: string;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { app, Tray, Menu, nativeImage } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { app, Tray, Menu, nativeImage } = electron;
|
||||
|
||||
let tray: Tray | null = null;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BrowserWindow, app } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { BrowserWindow, app } = electron;
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BrowserWindow, screen } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { BrowserWindow, screen } = electron;
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import electron from 'electron';
|
||||
const { contextBridge, ipcRenderer } = electron;
|
||||
import type { InklingApi, Note } from '@shared/types';
|
||||
|
||||
const api: InklingApi = {
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/renderer/inbox/main.tsx"></script>
|
||||
<script type="module" src="./main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/renderer/quickcapture/main.tsx"></script>
|
||||
<script type="module" src="./main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user