Skip to content

Core: Fix resolveImport TSX fallback#34815

Open
cyphercodes wants to merge 3 commits into
storybookjs:nextfrom
cyphercodes:fix-resolve-import-tsx-fallback
Open

Core: Fix resolveImport TSX fallback#34815
cyphercodes wants to merge 3 commits into
storybookjs:nextfrom
cyphercodes:fix-resolve-import-tsx-fallback

Conversation

@cyphercodes
Copy link
Copy Markdown
Contributor

@cyphercodes cyphercodes commented May 16, 2026

Fixes #34812

What I did

  • Added .tsx, .mtsx, and .ctsx fallbacks when resolveImport() cannot resolve .js, .mjs, or .cjs imports directly.
  • Kept the existing non-JSX TypeScript fallback precedence (.ts, .mts, .cts) before JSX fallbacks.
  • Added focused unit coverage for the new fallback paths and the existing .jsx -> .tsx behavior.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

No manual browser testing was necessary; this change is limited to the resolveImport() utility and is covered by targeted unit tests.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

AI assistance disclosure

This PR was implemented with assistance from OpenAI Codex.

Summary by CodeRabbit

  • Tests

    • Added a comprehensive test suite validating module import resolution fallback behavior across JavaScript and TypeScript extension scenarios, including creation and cleanup of temporary fixtures.
  • Bug Fixes

    • Improved import resolution fallback logic by centralizing extension mappings and exhaustively trying equivalents before surfacing errors, resulting in more reliable module resolution.

Review Change Stack


Written by an agent (Hermes Agent, gpt-5.5).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1eaf3ea4-d793-4582-9c1d-679f33dcd473

📥 Commits

Reviewing files that changed from the base of the PR and between 8bebdaf and dd6b9cf.

📒 Files selected for processing (1)
  • code/core/src/common/utils/interpret-files.ts

📝 Walkthrough

Walkthrough

Updated the resolveImport function to apply a centralized TypeScript extension fallback mapping for JS-like and JSX imports; the catch path iterates through all mapped TypeScript fallbacks and throws the last fallback error if none resolve. Added Vitest tests exercising the fallback ordering and resolution.

Changes

Import Resolution Fallback Enhancement

Layer / File(s) Summary
Fallback extension mapping and resolve logic
code/core/src/common/utils/interpret-files.ts
typescriptFallbackExtensions maps JS-like extensions to arrays of TypeScript equivalents; resolveImport now iterates through mapped fallbacks on resolve failure, accumulating the last error for reporting.
Test suite for fallback resolution
code/core/src/common/utils/__tests__/resolve-import.test.ts
Vitest tests create temporary fixture modules and validate fallback behavior: JS imports fall back to corresponding TypeScript variants, non-JSX TypeScript is preferred over JSX variants, and JSX imports resolve to TSX files; temporary directories are cleaned up after tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • storybookjs/storybook#33698: Changes core import-extension resolution logic using centralized extension fallback mapping for .js/.mjs/.cjs/.jsx to TypeScript alternatives with corresponding tests.
  • storybookjs/storybook#34692: Modifies code/core/src/common/utils/interpret-files.ts around resolveImport to use a different resolver (oxc-resolver) and .js/.jsx → .ts/.tsx fallback approach.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cyphercodes
Copy link
Copy Markdown
Contributor Author

Updated this PR to resolve the current next merge conflict in code/core/src/common/utils/interpret-files.ts.

What changed:

  • Merged latest upstream next into the PR branch.
  • Kept the TSX fallback behavior while aligning resolveImport with the upstream oxc-resolver implementation.

Local verification:

  • yarn install --immutable
  • yarn nx compile addon-vitest
  • yarn nx compile eslint-plugin
  • yarn vitest run --config code/core/vitest.config.ts code/core/src/common/utils/__tests__/resolve-import.test.ts ✅ (7 tests)
  • NODE_OPTIONS=--max_old_space_size=4096 yarn --cwd code lint:js:cmd core/src/common/utils/interpret-files.ts core/src/common/utils/__tests__/resolve-import.test.ts ✅ (0 errors; existing StorybookError warning in interpret-files.ts)
  • git diff --check HEAD~2..HEAD

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Fails
🚫

PR is not labeled with one of: ["ci:normal","ci:merged","ci:daily","ci:docs"]

Generated by 🚫 dangerJS against dd6b9cf

@cyphercodes cyphercodes changed the title Fix resolveImport TSX fallback Core: Fix resolveImport TSX fallback May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Empathy Queue (prioritized)

Development

Successfully merging this pull request may close these issues.

[Bug]: Manifest resolveImport() in interpret-files.ts missing .tsx fallback for .js extensions

3 participants