fix: add .js extensions to declaration file imports to resolve type re-export issue #64
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.
Summary
Fixes #X - Resolves the type re-export issue introduced when
package.jsonhas"type": "module"where types exported from this package could not be re-exported by consuming packages.Root Cause
When
package.jsonhas"type": "module", TypeScript treats.d.tsfiles as ESM modules, which require explicit file extensions (.js) for relative imports. The generated declaration files had imports likefrom './twist-api'instead offrom './twist-api.js', causing module resolution to fail when other packages tried to re-export types.This is the same issue that was fixed in todoist-api-typescript PR #410.
Changes
scripts/fix-dts-imports.cjs: Post-build script that adds.jsextensions to all relative imports in generated.d.tsfilesimportstatementsexportstatementsimport()type expressionspackage.json:build:fix-dtsscript to run the DTS fixerbuildscript to include the fix-dts stepattwscript for type validation using@arethetypeswrong/clifallback-conditionandfalse-esmrules (known limitations of dual-module packages that don't affect functionality)integrity-checksto includeattwvalidationBefore vs After
Before Fix
After Fix
Verification
Type Validation Results
Before fix (using
@arethetypeswrong/cli --pack):exportsresolution uses fallback conditions, unlike Node microsoft/TypeScript#50762)After fix:
InternalResolutionErrorthat prevented type re-exports is now resolvedTesting
You can verify this fix works by running:
npm install && npm run build npm run attwExpected output:
Test Plan
.jsextensions@arethetypeswrong/clireports no problemsCompatibility
Impact
Related Issues
This fix applies the same solution as:
The remaining warnings mentioned in the Todoist PR (
FalseESMandFallbackCondition) are expected for dual-module packages and are safely ignored:"type": "module") while CommonJS implementation has its ownpackage.json. This is intentional for dual-module packages.exportsfield has a known bug where it falls back to thetypescondition. This doesn't affect runtime behavior.🤖 Generated with Claude Code