-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preset-typescript does not work according to instructions #65
Comments
@rpolonsky what happens when you name that |
I'm running into the same problem. Changing the extensions from I was trying to create the smallest reproduction inside of a Next.js app. I think the issue stems from an incompatible For reference, here is my
A few notes:
|
@adam-beck Thanks for the thorough diagnosis! 🙌 How would you recommend improving the docs for your use case? |
For starters, it might be best to ensure that the The documentation could also mention which configuration options are absolutely necessary such as {
"compilerOptions": {
"module": "es6",
"jsx": "react",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
}
} It may be worthwhile to mention that those need to be set as is. Other than that, though, it's hard because each project has a unique
Edit: It looks like the demo components have typings already! I'm not sure why they aren't being picked up though. After searching, it looks like this has already been fixed too! |
I'm having the same issue, tried from scratch a few times, but having the same issue that @daraclare has. |
It looks to me like the problem is with the underlying webpack config. Running // ...
{
test: /\.tsx?$/,
use: [
{
loader: '/Users/joe/Projects/test/node_modules/ts-loader/index.js',
options: { transpileOnly: true }
},
{
loader: '/Users/joe/Projects/test/node_modules/react-docgen-typescript-loader/dist/index.js',
options: {}
}
],
include: []
},
// ... Notice the empty const path = require("path");
module.exports = [
{
name: "@storybook/preset-typescript",
options: {
include: [
path.resolve(__dirname, "../src"),
path.resolve(__dirname, "../stories")
]
}
}
]; ... everything works as expected and the relevant portion of the webpack config has the correct include directive: // ...
{
test: /\.tsx?$/,
use: [
{
loader: '/Users/joe/Projects/test/node_modules/ts-loader/index.js',
options: { transpileOnly: true }
},
{
loader: '/Users/joe/Projects/test/node_modules/react-docgen-typescript-loader/dist/index.js',
options: {}
}
],
include: [
'/Users/joe/Projects/test/src',
'/Users/joe/Projects/test/stories'
]
},
// ... Just for the sake of comparison, I checked the generated webpack config in a CRA project and found that it's using this: // ...
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: [
'/Users/joe/Projects/cra-test/src',
'/Users/joe/Projects/cra-test/.storybook'
],
// ... I'm not sure why the |
Looks like If we can take a note from CRA, maybe it could default to something more like this: const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
...
include = [
resolveApp('src'),
resolveApp('stories'),
resolveApp('.storybook')
] |
@wollardj I struggled trying to get this to work for a long time before I found this issue. Setting |
Good catch! I had been frustrated with this for a while, but setting these in |
I spend two work day for solve this issue. Then finally i solved it. Here is my solution step by step: First, i follow the for installing storybook Then i look up for typescript/cra support. doc
module.exports = {
stories: ['../src/components/**/*.stories.tsx'],
webpackFinal: config => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
}
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
};
Then Install following packages:
Problem is resolve path alias. You can solve this error like that: But i don't want to do that. That's why i add that config to
Note: There is no tricky things. I just follow the manual installation on storybook. |
This should be improved when v6 is released 🙏 |
@kylemh was it? I'm trying to get everything working but things blow up when I add @storybook/preset-typescript |
in v6, typescript support is internal you're not meant to use the preset |
I have a clean setup for storybook/react:
npx -p @storybook/cli sb init --type react
I added preset-typescript to new presets.js file like that
module.exports = ['@storybook/preset-typescript'];
and dependenciesnpm i -D @storybook/preset-typescript react-docgen-typescript-loader ts-loader
Now I have quite a simple basic configuration:
And instruction says that's it, but:
So how does it work?
The text was updated successfully, but these errors were encountered: