Skip to content

[codex] fix sdk ESM imports for Node#35

Merged
bcho merged 3 commits intomainfrom
fix-esm
Apr 7, 2026
Merged

[codex] fix sdk ESM imports for Node#35
bcho merged 3 commits intomainfrom
fix-esm

Conversation

@bcho
Copy link
Copy Markdown
Member

@bcho bcho commented Apr 7, 2026

Summary

Fix the TypeScript SDK package so Node can load its published ESM entrypoints without failing on extensionless relative imports.

What changed

  • switched internal ESM source imports to explicit .js specifiers
  • updated the ESM build to use NodeNext resolution
  • marked the package as "type": "module"
  • added an exports map for import and require
  • cleaned dist before builds and limited published files to the built package contents
  • bumped @absurd-sqlite/sdk to 0.3.0-alpha.2

Root cause

The SDK was publishing ESM files with extensionless relative imports. That works in some bundler-driven environments, but standard Node.js ESM resolution does not resolve those imports by default, which caused ERR_MODULE_NOT_FOUND at runtime.

Impact

Consumers can now install the published SDK tarball and import @absurd-sqlite/sdk directly under Node ESM without a postinstall patch.

Validation

  • npm test in sdks/typescript
  • npm pack
  • installed the packed tarball into a clean temp project
  • verified node -e 'import("@absurd-sqlite/sdk")'
  • verified queue creation and a spawned task with the packed SDK

@bcho bcho marked this pull request as ready for review April 7, 2026 05:11
@bcho bcho requested a review from Copilot April 7, 2026 05:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the TypeScript SDK’s packaging and build settings so the published package can be consumed by Node’s native ESM loader (avoiding ERR_MODULE_NOT_FOUND from extensionless relative imports).

Changes:

  • Updated internal relative imports to use explicit .js specifiers in ESM source.
  • Switched the ESM build to TypeScript NodeNext module/resolution to align with Node ESM behavior.
  • Updated package metadata for dual ESM/CJS consumption (type: module, exports map) and adjusted build/publish outputs.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdks/typescript/tsconfig.build.json Switches build output to Node-aligned ESM settings (NodeNext/nodenext).
sdks/typescript/src/sqlite-connection.ts Updates internal type imports to include .js extensions for Node ESM.
sdks/typescript/src/index.ts Updates imports/re-exports to include .js extensions for Node ESM.
sdks/typescript/package.json Adds type: module, exports map, cleans dist before build, and constrains published files.
sdks/typescript/package-lock.json Bumps package version metadata to 0.3.0-alpha.2.
Files not reviewed (1)
  • sdks/typescript/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"types": "dist/index.d.ts",
"files": [
"dist",
"README.md"
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new files allowlist omits LICENSE, so the published npm tarball will no longer include the license text even though the repo contains sdks/typescript/LICENSE. Consider adding LICENSE to the files array (or removing files if you want npm’s default include behavior).

Suggested change
"README.md"
"README.md",
"LICENSE"

Copilot uses AI. Check for mistakes.
],
"scripts": {
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"build": "rm -rf dist && tsc --project tsconfig.build.json && tsc --project tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm -rf dist (and the shell redirection/quoting used to write dist/cjs/package.json) is POSIX-shell specific and will fail under Windows’ default npm script shell. If this package is expected to build cross-platform, switch to a Node-based clean/write step (e.g., fs.rmSync / fs.writeFileSync) or a cross-platform tool like rimraf.

Suggested change
"build": "rm -rf dist && tsc --project tsconfig.build.json && tsc --project tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"build": "node -e \"require(\\\"fs\\\").rmSync(\\\"dist\\\", { recursive: true, force: true })\" && tsc --project tsconfig.build.json && tsc --project tsconfig.cjs.json && node -e \"const fs = require(\\\"fs\\\"); fs.mkdirSync(\\\"dist/cjs\\\", { recursive: true }); fs.writeFileSync(\\\"dist/cjs/package.json\\\", JSON.stringify({ type: \\\"commonjs\\\" }));\"",

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +13
"type": "module",
"main": "dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/cjs/index.js"
}
},
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime behavior change (adding type: module + an exports map to fix Node ESM loading) isn’t currently covered by automated tests. Consider adding a smoke test that builds (or uses prebuilt fixtures) and spawns a real node process to import('@absurd-sqlite/sdk') (and optionally require(...)) to prevent regressions in published entrypoints.

Copilot uses AI. Check for mistakes.
@bcho bcho merged commit e61b628 into main Apr 7, 2026
15 checks passed
@bcho bcho deleted the fix-esm branch April 7, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants