Repository navigation
fix(parser): ESM entry points fail with ERR_UNSUPPORTED_DIR_IMPORT - #181
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟡 2 medium 📍 Findings outside the diff (2) — 🟡 2 medium — defects on lines GitHub can't attach comments to🟡 Medium — // parser/package.json
15 "./v13": {
16 "import": "./wasm/v13.js",
17 "require": "./wasm/v13.cjs",
18 "types": "./wasm/v13.d.ts"
19 },
20 "./v14": {
21 "import": "./wasm/v14.js",
22 "require": "./wasm/v14.cjs",
23 "types": "./wasm/v14.d.ts"
24 },
25 "./v15": {
26 "import": "./wasm/v15.js",
🟡 Medium — // parser/scripts/prepare.js
210 fs.writeFileSync(
211 path.join(wasmDir, 'build-info.json'),
212 JSON.stringify(buildInfo, null, 2)
213 );When a version's wasm source is missing, The change reworks
Reviewed commit: d1d56e0 |
Summary
In Node,
import ... from '@pgsql/parser'(and every@pgsql/parser/vNNsubpath) throws when loaded with ESMimport.requireworks. Every published version I checked has this bug: 1.2.1, 1.5.0, 1.6.0 and 1.6.1.Cause:
parser/scripts/prepare.jsrewrites@pgsql/typesto the bundled./typesdirectory in every copied file. Node's ESM resolver rejects directory imports. CJSrequire('./types')and.d.tsresolution accept them, so only the ESM.jsfiles break. Bundlers resolve directories, which is probably why nobody reported it.Fix: ESM
.jsfiles now get./types/index.js..cjsand.d.tskeep./types.Test: the new
parser/test/esm.test.mjsimports the built root entry and each@pgsql/parser/vNNsubpath with ESMimport, then parses. Until now the parser tests only usedrequire('../wasm/index.cjs'), so this path never ran in CI.Repro evidence (local,
parser/wasmbuilt from the published 13.8.1–18.2.1 WASMs):esm.test.mjsfails withERR_UNSUPPORTED_DIR_IMPORTfor v13–v18.pnpm testinparser/passes 33/33 on Node 24.esm.test.mjspasses 7/7 on Node 20.20 and 22.23 too.@pgsql/parser@1.6.1tarball makes ESM import work on Node 20, 22 and 24.Link to Devin session: https://app.devin.ai/sessions/bcd8b2f791164247acb7a659b481efc2
Open in Devin Desktop: https://app.devin.ai/desktop/session/bcd8b2f791164247acb7a659b481efc2?variant=devin
Requested by: @pyramation