storybook icon indicating copy to clipboard operation
storybook copied to clipboard

Docgen: Errors on components whose names are keywords

Open preciselywilliam opened this issue 4 years ago • 17 comments

The storybook project builds fine: image

When I load the page I get a cryptic Javascript error: image

My deps are as below (let me know if there are other relevant deps):

    "@storybook/addon-a11y": "^6.0.5",
    "@storybook/addon-actions": "^6.0.5",
    "@storybook/addon-knobs": "^6.0.5",
    "@storybook/addon-links": "^6.0.5",
    "@storybook/addons": "^6.0.5",
    "@storybook/react": "^6.0.5",
    "@storybook/source-loader": "^6.0.5",
    "react": "16.13.1",

Not really sure where to start debugging, any ideas on what could be wrong?

preciselywilliam avatar Aug 13 '20 14:08 preciselywilliam

do you have a repro i can look at? i recently updated that part of the code and it's possible that you're hitting some kind of corner case bug

shilman avatar Aug 13 '20 16:08 shilman

do you have a repro i can look at? i recently updated that part of the code and it's possible that you're hitting some kind of corner case bug

I went through and disabled story by story until I found the one causing the crash. It was below, where Toaster is a function which has to be called as Toaster.create();

export default {
	title: 'Toaster',
	component: Toaster,
};

My mistake, thanks for having a look at the issue. I'll leave the issue open if you want to take further action. @shilman

preciselywilliam avatar Aug 14 '20 06:08 preciselywilliam

I had a similar problem in a project after upgrading Storybook, turned out I head a react component called delete in a file called delete.tsx and at some point Storybook tried to generate some code that looked something like delete.module = ... which caused the SyntaxError. Renaming the component and the file solved it (never checked which one was the problem).

TheKnarf avatar Aug 28 '20 19:08 TheKnarf

@TheKnarf

shilman avatar Aug 29 '20 01:08 shilman

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!

stale[bot] avatar Sep 20 '20 04:09 stale[bot]

@TheKnarf nailed this one. A file named delete.tsx causes this failure mode.

svvitale avatar Sep 29 '20 21:09 svvitale

Same issue here. In my case instead of having a file delete.tsx I had a switch.tsx which caused the same problem: (SyntaxError: Unexpected token '.')

pladaria avatar Oct 27 '20 18:10 pladaria

Yep, exactly the same issue here - I have switch.tsx which causes the same problem. Changing the file name to somethingElse.tsx everything compiles fine

boakenfull avatar Oct 30 '20 13:10 boakenfull

Same issue, (SyntaxError: Unexpected token '.') and switch.tsx :D

loelsonk avatar Nov 16 '20 22:11 loelsonk

switch.tsx too!

kilinkis avatar Nov 20 '20 11:11 kilinkis

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!

stale[bot] avatar Dec 25 '20 18:12 stale[bot]

Still a bug

svvitale avatar Dec 25 '20 19:12 svvitale

Same issue. For me it was a folder called switch with an index.tsx. Renaming the folder solved the issue.

Doenja avatar Feb 17 '21 15:02 Doenja

If you want this fixed, please upvote by adding a 👍 to the issue description. We use this to help prioritize!

shilman avatar Feb 18 '21 01:02 shilman

Please upvote the fix in https://github.com/styleguidist/react-docgen-typescript/pull/313

shilman avatar Feb 21 '21 23:02 shilman

Same issue. For me it was a folder called switch with an index.tsx. Renaming the folder solved the issue.

same here

Deboracgs avatar Jul 20 '21 10:07 Deboracgs

Manually set the display name solved this for me

switch.tsx ... Switch.displayName = 'Switch'; ...

PetterRuud avatar Jan 23 '22 17:01 PetterRuud

Manually set the display name solved this for me

switch.tsx ... Switch.displayName = 'Switch'; ...

Confirming this solution worked in my case. Nice fix @PetterRuud!

jorgenbuilder avatar Jan 12 '23 17:01 jorgenbuilder

I think this got fixed in 7.0 beta.

ndelangen avatar Jan 17 '23 22:01 ndelangen

As of 7.6.4 I'm still seeing this issue in Storybook. Above fixes work.

reify-benjamin-solum avatar Dec 08 '23 15:12 reify-benjamin-solum

Yeps, versions 7.6.12

If you had a problem with the switch component in the storybook, try changing it to "toogle", or similar names. The problem itself is the name guys

andreyna1808 avatar Feb 09 '24 12:02 andreyna1808