Skip to content
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

Docgen: Errors on TS components whose names are keywords #11419

Closed
pelotom opened this issue Jul 5, 2020 · 17 comments
Closed

Docgen: Errors on TS components whose names are keywords #11419

pelotom opened this issue Jul 5, 2020 · 17 comments

Comments

@pelotom
Copy link
Contributor

pelotom commented Jul 5, 2020

It appears that a change introduced in 6.0.0-beta.24 is causing my storybook to fail to load:

image

I'm not sure exactly what is going on here because source maps don't seem to be working.

@shilman
Copy link
Member

shilman commented Jul 5, 2020

Works in beta.23? Lots of changes in beta.24...

https://github.com/storybookjs/storybook/releases/tag/v6.0.0-beta.24

Do you have a repro?

@pelotom
Copy link
Contributor Author

pelotom commented Jul 5, 2020

Yes, it works in 6.0.0-beta.23 and before. I don't have a minimal repro currently, but can work on putting one together.

@baurine
Copy link

baurine commented Jul 15, 2020

Meet the same issue by 6.0.0-rc.3, details in #9514 (comment)

@baurine
Copy link

baurine commented Jul 15, 2020

related comment: #9514 (comment)

@pelotom
Copy link
Contributor Author

pelotom commented Jul 15, 2020

This seems to happen in cases where a static property is assigned to a component which is exported at its declaration site, e.g.

export default function Foo() {
  return null;
}
Foo.x = 42;

A workaround seems to be separating the export from the declaration:

function Foo() {
  return null;
}
Foo.x = 42;

export default Foo;

Class components with static properties suffer from the same problem:

export default class Foo() {
  static x = 42;
  render() { return null; }
}

and the workaround is the same:

class Foo() {
  static x = 42;
  render() { return null; }
}

export default Foo;

@baurine
Copy link

baurine commented Jul 16, 2020

Got it, thanks @pelotom !

@garrrettt
Copy link

I just had this exact same issue using Storybook v5.3.19 (current latest) and fixed it with the solution above.

@sibelius
Copy link

we got a weird Uncaught SyntaxError: Unexpected token '.' on 6.0.13

after fixing babel loose issue babel/babel#11622

@dangreen
Copy link

Uncaught SyntaxError: Unexpected token '.'

switch.stories.jsx:

import Switch from './switch'

export default {
  title: 'UI/Switch',
  decorators: [withKnobs],
  component: Switch,
}
try {
    // @ts-ignore
    switch.displayName = "switch"; // <==
    // @ts-ignore

@sibelius
Copy link

sibelius commented Sep 1, 2020

for us, the error was because we have some old stories without using CSF format

we just moved most of them to CSF and everything is fixed

@DanielHoffmann
Copy link

DanielHoffmann commented Sep 4, 2020

Still getting this error on storybook v6.0.21 (updating from v5.3.21) and @pelotom workaround works. It is definitely related to assigning after exporting (not only in the story, but anything the story imports).

I tried to create a minimum reproducible project:
https://github.com/DanielHoffmann/storybook-bug

to run:

npm install 
npm run storybook

but I could NOT reproduce the bug in a clean project. I imagine the problem is some mix of dependencies, maybe some babel configuration as I am using a custom webpack config in my storybook project

Also from my tests is also seems related to using this syntax in the code:

export { default as Something } from './someFile'

although I am not 100% sure

Unfortunately my whole codebase uses this pattern:

import gql from 'graphql-tag'
export function Component() {
  ...
}
Component.fragment = gql`
   fragment Component on Type {
      ...
   }
`

so I will refrain from updating until this has been figured out

@machinek56
Copy link

I my case the problem was in naming of component - default.tsx, changed it to simple.tsx resolved this issue.

ActuallyACat added a commit to cultureamp/kaizen-design-system that referenced this issue Oct 19, 2020
When static properties are assigned to a component when it is exported this seems to cause issues. Separating components from export fixed this. See: storybookjs/storybook#11419
@stale
Copy link

stale bot commented Dec 25, 2020

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 stale bot added the inactive label Dec 25, 2020
@phatNfqAsia
Copy link

phatNfqAsia commented Jan 8, 2021

I also experience this when my 'default.[exported-component]` is not understood by Storybook, which should be consider as unacceptable because the way I write code should not be affected by how a document-purpose framework works.

@stale stale bot removed the inactive label Jan 8, 2021
@sibelius
Copy link

image

it is happening again for us

Uncaught SyntaxError: Unexpected token '.'

can we disable react doc gen?

@sibelius
Copy link

related to #11980

@shilman shilman changed the title Uncaught SyntaxError: Unexpected token 'default' Docgen: Errors on TS components whose names are keywords Feb 21, 2021
@shilman
Copy link
Member

shilman commented Feb 21, 2021

closing as dupe to #11980

@shilman shilman closed this as completed Feb 21, 2021
ferni added a commit to OasisDEX/oasis-borrow that referenced this issue Mar 29, 2022
sennett pushed a commit to OasisDEX/oasis-borrow that referenced this issue Mar 30, 2022
* Organize css selectors.

* Update RouterContext import in Storybook.

* Separate export from declaration in all pages.

Workaround for fixing this Storybook issue: storybookjs/storybook#11419 (comment)

* Fix i18n in Storybook.

* Fix lint.

* Move getting the web3provider inside the widget.

* Upgrade uniswap widget package.

* Style token selection screen.

* Apply round borders to all blue buttons.

* Fix lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants