Skip to content

Commit 2f84bb3

Browse files
author
Evaggelos Balaskas
committed
fix(config): use namespace import for sander to bypass __esModule trap
Runtime warning in 3003d54's sander 0.5.1 -> 0.6.0 bump: 12 main.production.html:183 Boostnote resets the invalid configuration. console.warn @ main.production.html:183 get @ main.js:1268 (anonymous) @ main.js:36190 Diagnosed: ConfigManager.get() at browser/main/lib/ConfigManager.js:182 catches an exception from RcParser.parse() and emits the warning. RcParser.parse() at browser/lib/RcParser.js:9 calls sander.existsSync(...) which now throws TypeError because `sander.existsSync` resolved to undefined. Root cause: sander 0.6.0 added `Object.defineProperty(exports, '__esModule', { value: true })` at the top of dist/sander.cjs.js. sander 0.5.1 did NOT have this flag. Boostnote's RcParser used `import sander from 'sander'` — Babel 6 compiles this to `_interopRequireDefault(_sander)`: function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } For sander 0.5.1 (no __esModule flag): wraps -> `{ default: sander }` -> _sander2.default.existsSync resolves to the whole sander module's existsSync. Works. For sander 0.6.0 (__esModule: true): returns obj as-is -> _sander2.default looks up the `default` export, but sander 0.6.0 exposes only NAMED exports (appendFile, existsSync, readFileSync, ...) with no `default` property. _sander2.default is undefined. TypeError: Cannot read property 'existsSync' of undefined. Caught by ConfigManager's try/catch -> "Boostnote resets the invalid configuration" warning. Fires repeatedly because main.js:36190 has a `setInterval(() => ConfigManager.get(), 5 * 1000)` that re-runs every 5 seconds for theme refresh. After 60 seconds, 12 warnings stack up in DevTools console. Fix: switch to `import * as sander from 'sander'` (namespace import). Babel 6 compiles this to `_interopRequireWildcard(_sander)` which handles both ESM-flagged and bare CJS modules: when __esModule is true, returns the namespace directly (preserving all named exports); when false, builds a new object from enumerable own properties + default. Either way, the resulting `sander` binding has working existsSync / readFileSync / etc. methods. Single-file fix at browser/lib/RcParser.js:2 — the only file in browser/ that uses `import sander from 'sander'`. All other consumers use `const sander = require('sander')` (CJS form, no Babel interop — gets the raw module.exports namespace directly), which never hit this trap. Bundle compiles unchanged at 8.32 MB / 1141 modules. After this commit, RcParser.parse() correctly reads .boostnoterc, the catch block in ConfigManager.get() stops firing, and user customizations in .boostnoterc are no longer silently dropped. Sander 0.6.0 stays in place — the bump was correct; only the import style in RcParser needed updating to match modern Babel interop rules.
1 parent 8957543 commit 2f84bb3

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

browser/lib/RcParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import sander from 'sander'
2+
import * as sander from 'sander'
33

44
const BOOSTNOTERC = '.boostnoterc'
55
const homePath = global.process.env.HOME || global.process.env.USERPROFILE

0 commit comments

Comments
 (0)