Repository navigation
Build the Node package for Node's own ESM loader - #475
Merged
ospfranco merged 1 commit intoOct 28, 2026
Merged
Conversation
node/package.json is "type": "module", so Node loads node/dist as ESM, and its loader needs a full path in each relative import. The build used "moduleResolution": "bundler", which let "./database" through without an extension, so importing the package in Node failed with ERR_MODULE_NOT_FOUND. The Node build now compiles with "module" and "moduleResolution" "NodeNext", TypeScript's setting for code Node loads directly, and its relative imports name their ".js" files. The React Native package keeps "bundler" in the root tsconfig, which excludes node/. Fixes OP-Engineering#474 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #474.
node/package.jsonis"type": "module", so Node loadsnode/distas ESM, and Node's ESM loader needs a full path in every relative import. The Node build used"moduleResolution": "bundler", which let./databasethrough without an extension, soimport('@op-engineering/op-sqlite')in Node failed withERR_MODULE_NOT_FOUND.On the
nodenextquestion in the issue: TypeScript deprecated the oldnode10/noderesolution, notnode16/nodenext.nodenextis TypeScript's documented setting for code that Node itself loads, which is whatnode/distis.bundlerstays right for the React Native package, which Metro bundles, and this PR leaves it alone: the roottsconfig.jsonexcludesnode/.The change (
node/only):node/tsconfig.json:"module"and"moduleResolution"are"NodeNext".node/srcname their.jsfiles (./database.js,./types.js,./index.js). TypeScript now checks that each emitted import resolves under Node.node/jest.config.jsalready maps.jsimports back to the.tssources.Checked, building
node/with the repo's TypeScript (7.0.2) on Node 26:dist/index.jsimports./database, and loading it fails withERR_MODULE_NOT_FOUND.dist/index.jsimports./database.js, and Node loads it with all its exports (Database,open,openSync,openV2, …).node/src/test.spec.ts, run from its compileddist/test.spec.jswith Jest: 18 pass, before and after. Jest's own resolver accepts extensionless imports, which is why the tests never showed this.yarn installfrom the lockfile, onmainand on this branch:yarn typecheck(CI's check) passes on both.yarn prepare(bob build && yarn build:node) builds both packages.npm packships the samenode/distfiles as before.yarn lintreports the same two errors on both, indocs/tsconfig.jsonandtest_transaction.js, which this PR doesn't touch.One thing I noticed but didn't touch:
yarn test:nodecan't run onmainas it is, because ts-jest needs TypeScript's JavaScript API, which TypeScript 7 doesn't ship ("does not expose the JavaScript compiler API required by ts-jest"). That happens with or without this PR.🤖 Generated with Claude Code