Conversation
There was a problem hiding this comment.
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
.jsspecifiers in ESM source. - Switched the ESM build to TypeScript
NodeNextmodule/resolution to align with Node ESM behavior. - Updated package metadata for dual ESM/CJS consumption (
type: module,exportsmap) 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.
sdks/typescript/package.json
Outdated
| "types": "dist/index.d.ts", | ||
| "files": [ | ||
| "dist", | ||
| "README.md" |
There was a problem hiding this comment.
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).
| "README.md" | |
| "README.md", | |
| "LICENSE" |
sdks/typescript/package.json
Outdated
| ], | ||
| "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", |
There was a problem hiding this comment.
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.
| "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\\\" }));\"", |
| "type": "module", | ||
| "main": "dist/index.js", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/cjs/index.js" | ||
| } | ||
| }, |
There was a problem hiding this comment.
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.
Summary
Fix the TypeScript SDK package so Node can load its published ESM entrypoints without failing on extensionless relative imports.
What changed
.jsspecifiersNodeNextresolution"type": "module"exportsmap forimportandrequiredistbefore builds and limited published files to the built package contents@absurd-sqlite/sdkto0.3.0-alpha.2Root 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_FOUNDat runtime.Impact
Consumers can now install the published SDK tarball and import
@absurd-sqlite/sdkdirectly under Node ESM without a postinstall patch.Validation
npm testinsdks/typescriptnpm packnode -e 'import("@absurd-sqlite/sdk")'