diff --git a/src/common/objects.ts b/src/common/objects.ts index ec56614..c054d12 100644 --- a/src/common/objects.ts +++ b/src/common/objects.ts @@ -10,8 +10,11 @@ export async function tryLoadJSON5() { // @ts-ignore if (globalThis.JSON5) JSON5 = globalThis.JSON5; else { - const t = await import('json5'); - JSON5 = (t.default || t) as never; + if (typeof require === 'function') JSON5 = require('json5'); + else { + const t = await import('json5'); + JSON5 = (t.default || t) as never; + } } } catch { // quit diff --git a/src/node/LiteStorage.ts b/src/node/LiteStorage.ts index 1bae36c..bac2387 100644 --- a/src/node/LiteStorage.ts +++ b/src/node/LiteStorage.ts @@ -1,7 +1,7 @@ import { homedir } from 'node:os'; import { dirname, resolve } from 'node:path'; import { fs } from './fs-system'; -import { assign, safeJsonParse, safeStringify } from '../common/objects'; +import { assign, safeJsonParse, safeStringify, tryLoadJSON5 } from '../common/objects'; export interface LSCache { version: string; @@ -98,6 +98,7 @@ export class LiteStorage> { const TOML = await import('@iarna/toml'); localCache = JSON.parse(JSON.stringify(TOML.default.parse(content))); } else { + await tryLoadJSON5(); localCache = safeJsonParse(content, true) as LSCache; }