storybookjs/storybook

[DX] Favor `.tsx` extension in Vite/React/TS framework

开放

#21,306 创建于 2023年2月28日

 (0 条评论) (1 个反应) (0 位负责人)TypeScript (10,058 个派生)batch import
clihelp wantedmaintenance

仓库指标

星标
 (89,909 个星标)
PR 合并指标
 (平均合并 7天 22小时) (30 天内合并 184 个 PR)

描述

Describe the bug

This is not a code bug but an misalignment in developer expectations.

The Vite/React/TS framework uses .ts extensions for Stories and configuration. However, .tsx is required when adding React components (decorators and templates).

On the story page, the Vite provided error is misleading (screenshot attached): Failed to find dynamically imported module: **/MyComponent.stories.ts

image

This is a little confusing because a file by that name exists (on the user filesystem). The file just failed to build the included JSX.

The correct error can be seen in both console and and docs page: [plugin:vite:esbuld] Transform failed… image

Documentation does not assist here because it is based on the Webpack experience, which is much more permissive. Docs suggest that .tsx or .ts are suitable.

To Reproduce

  • npx storybook@next repro
    • resolved as: storybook@7.0.0-beta.55
  • framework: TS/React/Vite
  • node: 16.13.2
  • Add any decorator or render field to a story

If the file extensions aren't changed to .tsx, they produce these errors:

image image image

System

No response

Additional context

I spoke with the Storybook team in internal Chromatic chat. The favored solution there is to use use .tsx files in this sandbox, even though the extension is extraneous for the CSF3 examples.

贡献者指南