Skip to content

Fix TypeScript module resolution for direct filter imports#119

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-95
Draft

Fix TypeScript module resolution for direct filter imports#119
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-95

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 12, 2025

This PR fixes a TypeScript module resolution issue that occurs when users upgrade to Style Dictionary v4 and switch to modern module resolution strategies (moduleResolution: "bundler", "node16", or "nodenext").

Problem

When importing filters directly, users encountered the following error:

import { isDuration } from 'style-dictionary-utils/dist/filter/isDuration.js'
import { isDimension } from 'style-dictionary-utils/dist/filter/isDimension.js'
Cannot find module 'style-dictionary-utils/dist/filter/isDuration.js' or its corresponding type declarations.ts(2307)

Root Cause

The package.json exports configuration was missing explicit type declarations for subpath exports:

"exports": {
  ".": "./dist/index.js",
  "./filter/*": "./dist/filter/*"
}

Modern TypeScript module resolution requires explicit declaration of both JavaScript files and their corresponding TypeScript declaration files.

Solution

Updated the exports configuration to properly specify both .js and .d.ts files:

"exports": {
  ".": {
    "import": "./dist/index.js",
    "types": "./dist/index.d.ts"
  },
  "./filter/*.js": {
    "import": "./dist/filter/*.js",
    "types": "./dist/filter/*.d.ts"
  },
  "./dist/filter/*.js": {
    "import": "./dist/filter/*.js",
    "types": "./dist/filter/*.d.ts"
  }
}

This fix supports both import patterns:

  • Documented pattern: import { isDuration } from 'style-dictionary-utils/filter/isDuration.js'
  • User pattern from issue: import { isDuration } from 'style-dictionary-utils/dist/filter/isDuration.js'

Verification

  • ✅ All existing tests pass (131/131)
  • ✅ TypeScript compilation works with bundler, node16, and nodenext module resolution
  • ✅ Both main imports and direct filter imports work correctly
  • ✅ Maintains full backward compatibility

This is a minimal change that only updates the package.json exports configuration without modifying any source code.

Fixes #95.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
Copilot AI changed the title [WIP] Types no longer found when importing filters directly Fix TypeScript module resolution for direct filter imports Jun 12, 2025
Copilot AI requested a review from lukasoppermann June 12, 2025 13:19
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.

Types no longer found when importing filters directly

2 participants