-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Bug?]: TS error in preview.tsx
& main.ts
when using absolute (src/
-prefixed) and/or component directory imports [storybook-vite]
#11741
Comments
This is an issue that touches codegen that I am not familiar with — there's a bunch of magic that happens when you eg run Is this breaking anything? The syntactic sugar of being able to use an absolute import is certainly nice, but enabling it here may not be worth the investment. @Tobbe, can you weigh in here? |
You can add .storybook folder to .tsconfig like: "include": [
"src",
"config",
"./.storybook/**/*",
"../.redwood/types/includes/all-*",
"../.redwood/types/includes/web-*",
"./types"
] This allows to use relative imports |
My problem with storybook it's that mockCurrentUser just doesn't work, even with the provider as decorator |
Also, eslint does not work for this files with current eslint config |
I've never actually worked with Storybook, so I feel a bit outside of my comfort zone with this one 😬 |
Generate a component, then open up
vs. what you would expect to work (as it does everywhere else in the RW stack)
Noteworthy:
So summing up this is only a QOL / DX bug, not a big showstopper. But it looks like it may be easily fixable, as it feels like somewhere the storybook config path simply needs to be included. |
@irg1008 i think this nails it, cheers I guess during the move from from This solves all issues above 🥳 |
Is this mocked useAuth being used in storybook right now? |
useAuth not being mocked up when inside storybookAbout this. I fixed it. I think I need to point out how and what I did wrong. For storybook auth mock we use: In the script we can see the path detected for transformation is
When moving our auth.ts file from root folder to let's say "lib" folder, storybook is not able to find the file and therefore replace it with the mock.
It's an issue with me since I change the file location but could we provide a way to set auth file location or maybe add some common paths like 'lib/auth' or similar? |
@irg1008 Apart from this being slightly off-topic in this issue here – i'm not sure what you mean. Shouldn't we simply use |
Yeah sorry about that, I meant that the location of auth.ts file on the web side it's mandatory to be on the root folder. Otherwise the storybook plugin won't pick it up and mock it, making mockCurrentUser function to use the original unmocked function |
Ah i see, thanks for the explanation. I guess that would be defined somewhere in the |
Ah yeah that's another gotcha. I solved it by adding I've now created #11748 to rectify that as well. |
I wouldn't be surprised if this also breaks other things. We probably assume the location of your auth file is at Anyway, if we can make this configurable for Storybook I'm all for that 🙂 |
Oh yay!!!! Yup, that's my mistake :) I'm still more comfortable using the framework and still a little newer to building the framework. |
Ditto on this :) Didn't even occur to me that anyone would want to move that. @irg1008 what was your reason for moving it? And have you run into any other issues related to it? |
None, I thought moving this file didn't mean anything, so I moved it to lib to match the api folder structure somehow. I think that if we don't have file based routing, we shouldn't have to have this constraint for specific file locations Or maybe some sort of way to customize the paths. Anyway it's not big deal, just moved it back to the root folder |
What's not working?
As reported in the forum during the storybook migration from webpack to vite:
Above squiggles amount to
Cannot find module '{import path}' or its corresponding type declarations.
. Storybook compiles fine though with not complaints whatsoever.@arimendelow
Current workaround
Use relative imports and specify the full component path (i.e.
../src/components/ConfirmDialog/ConfirmDialog
works for the above example).How do we reproduce the bug?
main.ts
orpreview.tsx
inweb/.storybook
src/
or any path to a component that only refers to the component directory (i.e.../src/components/MyComponent
instead of../src/components/MyComponent/MyComponent
)What's your environment? (If it applies)
Are you interested in working on this?
The text was updated successfully, but these errors were encountered: