storybook: [6.0.0-beta.2] Storybook v6 not working with Typescript
Describe the bug
Using the Storybook v6 beta with @storybook/preset-typescript fails, throwing an error for loading JSX in stories.
Minimal repro has this error:
File was processed with these loaders:
* ./node_modules/@storybook/source-loader/dist/index.js
You may need an additional loader to handle the result of these loaders.
| };
|
> export const Basic = () => <Button>Click me</Button>;
|
at Object../src/components/Button/Button.stories.tsx
To Reproduce Steps to reproduce the behavior:
- Install
@storybook/react@nextand@storybook/preset-typescript@next - Write a story and import your typescript compoent
- Watch it fail
Expected behavior Should be able to load Typescript components/stories and load JSX
Screenshots

System:
System:
OS: macOS 10.15.4
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Binaries:
Node: 11.12.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.14.3 - /usr/local/bin/npm
Browsers:
Chrome: 81.0.4044.129
Firefox: 74.0
Safari: 13.1
npmPackages:
@storybook/addon-docs: next => 6.0.0-beta.2
@storybook/addon-essentials: next => 6.0.0-beta.2
@storybook/addons: next => 6.0.0-beta.2
@storybook/preset-typescript: ^3.0.0 => 3.0.0
@storybook/react: next => 6.0.0-beta.2
Additional context N/A
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 22 (9 by maintainers)
Are there any solutions? I’m having the same issue on v6.5.9.
Hi everyone! Seems like there hasn’t been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don’t have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
I just replied in this thread #9610 with a similar issue happening with @storybook/react v6.3.10 what seems to happen is that typescript transpiles modules to
EsNext(ESM) but the ts-node or typescript used in storybook parses it as aCommonJsfile, so it givesUnexpected token 'export'error.We’ve just released zero-config typescript support in 6.0-beta. Please upgrade and test it!
Thanks for your help and support getting this stable for release!
For what it’s worth, I have the exact same issue as original poster. It’s also in a private repo, and interestingly I’m noticing this on a setup that doesn’t yet involve consuming any custom stories or any of my own code – I’ll see if I can repro in a fresh repo but it does seem suggestive that running this in a root directory with no custom stories and no custom config, yet the build step fails to parse the TS from the initialized stories.
It’s in a private repo unfortunately, but reducing to a minimum repro with the following config still has the same error:
main.js
Button.story.tsx
tsconfig.json