Storybook 4 + create-react-app 2 + Typescript: loader issue
See original GitHub issueDescribe the bug I’m trying to setup a storybook using the guidelines here: https://storybook.js.org/configurations/typescript-config, but this doesn’t seem to be accurate (anymore).
To Reproduce
npx create-react-app my-app
yarn add -D typescript @types/node @types/react @types/react-dom @types/jest
Rename react files from .js to .ts/.tsx
npx -p @storybook/cli sb init
yarn add -D awesome-typescript-loader
yarn add -D @types/storybook__react
yarn add -D @storybook/addon-info react-docgen-typescript-webpack-plugin
Results in following depedencies:
{
"dependencies": {
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-scripts": "2.1.1"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@storybook/addon-actions": "^4.0.4",
"@storybook/addon-info": "^4.0.4",
"@storybook/addon-links": "^4.0.4",
"@storybook/addons": "^4.0.4",
"@storybook/react": "^4.0.4",
"@types/jest": "^23.3.9",
"@types/node": "^10.12.2",
"@types/react": "^16.4.18",
"@types/react-dom": "^16.0.9",
"@types/storybook__react": "^3.0.9",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.4",
"react-docgen-typescript-webpack-plugin": "^1.1.0",
"typescript": "^3.1.6"
}
}
Copy tsconfig.json + .storybook/webpack.config.js from https://storybook.js.org/configurations/typescript-config/
Add simple button component:
// src/components/button/Button.tsx
import * as React from "react";
interface ButtonProps {
label: string
}
export const Button: React.SFC<ButtonProps> = (props) => {
return <button>{props.label}</button>;
}
Add Storybook config
// .storybook/config.ts
import { configure } from '@storybook/react';
const req = require.context('../src/stories', true, /\.tsx$/);
configure(() => {
req.keys().forEach(filename => req(filename));
}, module);
Add story
// src/stories/index.tsx
import React from 'react';
import { storiesOf } from '@storybook/react';
import { Button } from '../components/button/Button';
const stories = storiesOf('Button', module);
stories.add(
'test',
() => <Button>Test</Button>,
);
Expected behavior
yarn storybook should mount a storybook with one story.
Screenshots

Code snippets
I also had to remove "isolatedModules": true from tsconfig.json before I could get the storybook running.
System:
- OS: MacOS
- Browser: Chrome
- Framework: react
- Version: 4.0.4
Additional context Storybook 4 + create-react-app 2.1 without typescript enabled works like a charm 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Typescript React app is throwing error when using the new ...
I wanted to use the new satisfies operator in my Typescript React app but it doesn't works. here are the package.json and typescript...
Read more >TypeScript Config - Storybook
This is a central reference for using Storybook with TypeScript. Setting up TypeScript with awesome-typescript-loader. Dependencies you may need.
Read more >Cannot start React App after installing Storybook? Here's how ...
The Problem When Starting React · 1. Delete package-lock. · 2. Delete node_modules in your project folder. · 3. Remove "babel-loader" from ...
Read more >@storybook/preset-create-react-app - npm
Create React App preset for Storybook. Latest version: 4.1.2, last published: 3 months ago. Start using @storybook/preset-create-react-app ...
Read more >react-docgen-typescript-loader - npm package - Snyk
An important project maintenance signal to consider for react-docgen-typescript-loader is that it hasn't seen any new versions released to npm in the past...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@mohamedmansour this works like a charm indeed:
no need for
awesome-typescript-loaderanymore.@vitalybe @igor-dv
Upgraded to storybook 4.0.6 and using this as webpack.config.js:
This works and has live type validation, it’s based on the config in
react-scripts, so all dependencies are already loaded if you use CRA 2.