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

TypeError: (tag.text || "").trim is not a function #356

Closed
damiangreen opened this issue May 21, 2021 · 31 comments · Fixed by #360
Closed

TypeError: (tag.text || "").trim is not a function #356

damiangreen opened this issue May 21, 2021 · 31 comments · Fixed by #360

Comments

@damiangreen
Copy link

We're getting this on node_modules/react-docgen-typescript/src/parser.ts:750:44
When running yarn run build-storybook
with the latest typescript ^4.4.0-dev.20210521, also doesnt work with 4.3

@alexeagleson
Copy link

Getting the same error on typescript 4.3.1-rc

@adharris
Copy link

This seems to be related to using @ tags in the doc comment. Removing them, while undesirable, appears to make this error go away.

@erik-beus
Copy link

This seems to be related to using @ tags in the doc comment. Removing them, while undesirable, appears to make this error go away.

We don't use any @ tags in our doc comments, but we still get the error 🤷

@adharris
Copy link

For me, it the vast majority comes from when i extend built in html props:

interface Props extends HTMLProps<HTMLDivElement> {
   /...
}

Those built in ones have @see directives all over the place

@nickbouton
Copy link

nickbouton commented May 26, 2021

Having the exact same error with anything we export as Meta since upgrading to TypeScript 4.3.2.

image

This is the relevant line: https://github.com/styleguidist/react-docgen-typescript/blob/master/src/parser.ts#L750

Temporary workaround for now was just to disable reactDocgen entirely:

  typescript: {
    reactDocgen: 'none',
  },

@nickbouton
Copy link

nickbouton commented May 26, 2021

FYI, did a little further digging here and it seems to be something (jsdoc seems likely) in our Material UI components that's triggering the issue. We're using Material UI core @ 4.11.4 and even importing + referencing something as simple as a Link alone is enough to set it off.

e.g. a quick replace of our Link component gets this story to pass:
image

e.g. this actually fails (notice additional LinkProps type import):
image

@michelengelen
Copy link
Contributor

we had the same issue in our storybook project and I could (temporarily) solve it by resetting typescript to 4.2.2.
I will have a look at this issue though, so stay tuned! :D

@michelengelen
Copy link
Contributor

Ok, I had a quick look into the problem. TScompiler now returns a different (and IMO improved value) from getJsDocTags. The now split the description/text into the correct use-cases (paramName, space and description).

The problem is, that there are several other changes introduced and right now this package is built upon using a locked TS version of 3.5.2. That means several other problems occur when bumping the version to a more recent (4.3.2) and I do not know if that is an expected change from @pvasek ?

If it is OK i would like to take up this task and bump the version and fix all errors that might occur with it, fixing this issue along the line.

I would also suggest to improve the tagMap on the JSDoc type to be a real map of sorts with a new structure (this would mean a major change though).

The new structure could look something like this:

tagMap: {
    type: string;    // <-- can be one of the `@` types from JSDoc (`@returns`, `@param`, etc)
    name?: string;    // <-- the parameter name
    description?: string;    // <-- the parameter description
}

@DustinBrett
Copy link

DustinBrett commented May 27, 2021

I noticed this same issue and edited the node_module so I could take a look at tag and what text is. It seems to now be an array of elements. The tag I got my failure on was:

{
  name: 'see',
  text: [
    { text: 'https', kind: 'text' },
    {
      text: '://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute',
      kind: 'text'
    }
  ]
}

Which I may have tracked down to this JSDoc tag. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L1869.

I am wondering if this @see tag had been in a different format such as the one mentioned here https://jsdoc.app/tags-see.html (* @see {@link ...}). Maybe it would have worked and returned a string to tag.text or possibly in TypeScript 4.3 it will always return an array of these { text, kind } (SymbolDisplayPart) objects.

I see on this line (https://github.com/styleguidist/react-docgen-typescript/blob/master/src/parser.ts#L744) that react-docgen-typescript is making use of getJsDocTags which I think may be involved in this.

I did some digging into the TS 4.3 update and I wonder if this change (https://devblogs.microsoft.com/typescript/announcing-typescript-4-3/#jsdoc-link-tags) could be involved. The PR (https://github.com/microsoft/TypeScript/pull/41877/files#diff-c989327fa8e0b2f600be4a19bc5b6f2cc2e9d157e8b2b85917645ecfa4df4652R157) for that change mentions changing the way @see tags are parsed.

image

Anyway that is my initial looking around, hopefully helps someone. In our case we have just reverted from TS 4.3 in the interim.

@michelengelen
Copy link
Contributor

That definitely helps to understand the reasoning behind the change ... I already found out about the new structure as mentioned above.

I am currently looking into solving this. Stay tuned!

@farukbigez
Copy link

not a fix but downgrading typescript to 4.2.2 covers up the issue but not fixing it. for lazy programmers: yarn add --dev typescript@4.2.2

@tdeo
Copy link

tdeo commented May 28, 2021

I was having the same issue when upgrading typescript from 4.2.4 to 4.2.3, and I think that's because of the parser trying to parse some incompatible JSdoc from the node_modules code.

In my case I'm able to avoid this issue by configuring the plugin to only include my app source code :

new ReactDocgenTypescriptPlugin({
  include: ['app/javascript/**/*.tsx'],
})

@Haraldlons
Copy link

In which file is this?

Temporary workaround for now was just to disable reactDocgen entirely:

  typescript: {
    reactDocgen: 'none',
  },

@erik-beus
Copy link

In which file is this?

Temporary workaround for now was just to disable reactDocgen entirely:

  typescript: {
    reactDocgen: 'none',
  },

.storybook/main.js in module.exports
See docs here https://storybook.js.org/docs/react/configure/typescript

m7kvqbe1 added a commit to Royal-Navy/design-system that referenced this issue Jun 1, 2021
styleguidist/react-docgen-typescript#356

Storybook builds fail with the latest TypeScript release `4.3.2`.

Resolving to an earlier stable release for now.
m7kvqbe1 added a commit to Royal-Navy/design-system that referenced this issue Jun 1, 2021
storybookjs/storybook#15067

styleguidist/react-docgen-typescript#356

Storybook builds fail with the latest TypeScript release `4.3.2`.

Resolving to an earlier stable release for now.
driskull added a commit to Esri/calcite-design-system that referenced this issue Aug 20, 2021
* build(deps): bump versions

* build(deps): bump versions

* disable reactDoggen

styleguidist/react-docgen-typescript#356 (comment)

* revert typescript bump

* fix package lock
@AvOeffelen
Copy link

AvOeffelen commented Aug 24, 2021

Had the same on Storybook 6.2.*, updated to v6.3.7 and the problem is solved!

simenko added a commit to simenko/precise-ui that referenced this issue Sep 6, 2021
glenngijsberts added a commit to TicketSwap/solar that referenced this issue Sep 6, 2021
the latest typescript version is using a 3rd party script that's having some type errors. More info
here styleguidist/react-docgen-typescript#356
bobbonius pushed a commit to TicketSwap/solar that referenced this issue Sep 6, 2021
the latest typescript version is using a 3rd party script that's having some type errors. More info
here styleguidist/react-docgen-typescript#356
@jackdh
Copy link

jackdh commented Sep 16, 2021

Still getting this on 6.3.8.

Disabling it as per @Haraldlons comment still works.

YingJiangHui added a commit to YingJiangHui/neat-ui-react that referenced this issue Sep 21, 2021
原因:
1. react-docgen-typescript 依赖不支持 typescript@v4.3.2+
issue url:styleguidist/react-docgen-typescript#356

2. dumi 暂时没有开放对react-docgen-typescript过滤功能的配置
issue url:umijs/dumi#513
@byzg
Copy link

byzg commented Nov 25, 2021

I was having the same issue when upgrading typescript from 4.2.4 to 4.2.3, and I think that's because of the parser trying to parse some incompatible JSdoc from the node_modules code.

In my case I'm able to avoid this issue by configuring the plugin to only include my app source code :

new ReactDocgenTypescriptPlugin({
  include: ['app/javascript/**/*.tsx'],
})

this is woring without change version! Dude you save my day!

@graup
Copy link

graup commented Feb 8, 2022

In my case, updating storybook didn't solve this. I have the outdated react-docgen-typescript-loader package as a dependency, which uses an old version of react-docgen-typescript. I solved it by adding this to my yarn.lock:

  "resolutions": {
    "react-docgen-typescript": "2.2.2"
  }

You can also try to remove any entry of react-docgen-typescript from your lock file and run install again, maybe this is enough.

@john1625b
Copy link

I was having the same issue when upgrading typescript from 4.2.4 to 4.2.3, and I think that's because of the parser trying to parse some incompatible JSdoc from the node_modules code.
In my case I'm able to avoid this issue by configuring the plugin to only include my app source code :

new ReactDocgenTypescriptPlugin({
  include: ['app/javascript/**/*.tsx'],
})

this is woring without change version! Dude you save my day!

@byzg
What file does this go in?

@lazarok09
Copy link

I was having the same issue when upgrading typescript from 4.2.4 to 4.2.3, and I think that's because of the parser trying to parse some incompatible JSdoc from the node_modules code.
In my case I'm able to avoid this issue by configuring the plugin to only include my app source code :

new ReactDocgenTypescriptPlugin({
  include: ['app/javascript/**/*.tsx'],
})

this is woring without change version! Dude you save my day!

@byzg What file does this go in?

is on main.js of storybook

luxuereal added a commit to luxuereal/wallet-Asgardex-electron that referenced this issue Jun 16, 2023
## Notes

- `yarn.lock` has been created from scratch (by removing it before running `yarn`)
- Node version update to `14.17` (as same as Electron@13 is using - see https://www.electronjs.org/releases/stable?version=13&page=2#13.0.0)
- `.storybook/main.js` defines `reactDocgen: 'react-docgen'` temporary (just as a workaround as mentioned in styleguidist/react-docgen-typescript#356 (comment))
- Upgrades to latest react-chart | chartjs@3.x needs updates for data and style handling for `PoolDetailsChart*.ts`
- Stick on `cosmos-client@0.39.2` (even a minor update to `@0.39.13` breaks tests - see https://github.com/thorchain/asgardex-electron/pull/1579/checks?check_run_id=2903609210#step:8:27)
- Following packages could not be updated (similar issues we had before in thorchain/asgardex-electron#1411)

```bash
ncu
Checking asgardex-electron/package.json
[====================] 105/105 100%

 @storybook/react  ^6.1.21  →   ^6.3.0 // breaks build of storybook, it seems babel loader version is not compatible with current CRA (as mentioned in #1411)
 @types/node        ^14.17  →   ^15.12 // we stick on Node@14.17 used by Electron@13.x  
 ts-loader          ^8.3.0  →   ^9.2.3 // not compatible w/ webpack <5.0 - see https://github.com/TypeStrong/ts-loader/releases/tag/v9.0.0
 cosmos-client     ^0.39.2  →  ^0.42.5 // `xchain-cosmos` needs to be updated before
 ethers             ^5.1.4  →   ^5.3.1 // `xchain-ethereum` needs to be updated before 
 rxjs               ^6.6.7  →   ^7.1.0 // `fp-ts-rxjs` + `@devexperts/rx-utils/dist/observable.utils` still depends on rxjs@6.x
 ```
luxuereal added a commit to luxuereal/wallet-Asgardex-electron that referenced this issue Dec 11, 2023
## Notes

- `yarn.lock` has been created from scratch (by removing it before running `yarn`)
- Node version update to `14.17` (as same as Electron@13 is using - see https://www.electronjs.org/releases/stable?version=13&page=2#13.0.0)
- `.storybook/main.js` defines `reactDocgen: 'react-docgen'` temporary (just as a workaround as mentioned in styleguidist/react-docgen-typescript#356 (comment))
- Upgrades to latest react-chart | chartjs@3.x needs updates for data and style handling for `PoolDetailsChart*.ts`
- Stick on `cosmos-client@0.39.2` (even a minor update to `@0.39.13` breaks tests - see https://github.com/thorchain/asgardex-electron/pull/1579/checks?check_run_id=2903609210#step:8:27)
- Following packages could not be updated (similar issues we had before in thorchain/asgardex-electron#1411)

```bash
ncu
Checking asgardex-electron/package.json
[====================] 105/105 100%

 @storybook/react  ^6.1.21  →   ^6.3.0 // breaks build of storybook, it seems babel loader version is not compatible with current CRA (as mentioned in #1411)
 @types/node        ^14.17  →   ^15.12 // we stick on Node@14.17 used by Electron@13.x  
 ts-loader          ^8.3.0  →   ^9.2.3 // not compatible w/ webpack <5.0 - see https://github.com/TypeStrong/ts-loader/releases/tag/v9.0.0
 cosmos-client     ^0.39.2  →  ^0.42.5 // `xchain-cosmos` needs to be updated before
 ethers             ^5.1.4  →   ^5.3.1 // `xchain-ethereum` needs to be updated before 
 rxjs               ^6.6.7  →   ^7.1.0 // `fp-ts-rxjs` + `@devexperts/rx-utils/dist/observable.utils` still depends on rxjs@6.x
 ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.