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

react-docgen-typescript: Cannot read property 'length' of undefined #15153

Closed
hazem3500 opened this issue Jun 6, 2021 · 3 comments
Closed

react-docgen-typescript: Cannot read property 'length' of undefined #15153

hazem3500 opened this issue Jun 6, 2021 · 3 comments

Comments

@hazem3500
Copy link

Describe the bug
In storybook, I get the error

70% sealing React Docgen Typescript Plugin __PATH__\node_modules\react-docgen-typescript\lib\parser.js:577
            if (functionStatement && functionStatement.parameters.length) {
                                                                  ^

TypeError: Cannot read property 'length' of undefined

my typescript version is 4.2.4

System
Environment Info:

System:
OS: Windows 10 10.0.18362
CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Binaries:
Node: 14.8.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files\nodejs\yarn.CMD
npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 91.0.4472.77
Edge: Spartan (44.18362.449.0)
npmPackages:
@storybook/addon-a11y: ^6.1.9 => 6.2.9
@storybook/addon-essentials: ^6.1.9 => 6.2.9
@storybook/preset-typescript: ^3.0.0 => 3.0.0
@storybook/react: ^6.1.6 => 6.2.9

@shilman
Copy link
Member

shilman commented Jun 6, 2021

Try removing preset-typescript. Typescript support is built-in after SB6.0.

Also, can you please create a reproduction by running npx sb@next repro, following the instructions, and linking it in your issue description? We prioritize issues with reproductions over those without. Thank you! 🙏

@hazem3500
Copy link
Author

While I couldn't isolate the problem to create a reproduction, I've used patch-package to make a monkey patch for react-docgen-typescript that solved the problem.

I've changed the line

if (functionStatement && functionStatement.parameters.length)

to

if (functionStatement && functionStatement.parameters && functionStatement.parameters.length)
Monkey Patch
diff --git a/node_modules/react-docgen-typescript/lib/parser.js b/node_modules/react-docgen-typescript/lib/parser.js
  index d24f3c8..fe1ab44 100644
  --- a/node_modules/react-docgen-typescript/lib/parser.js
  +++ b/node_modules/react-docgen-typescript/lib/parser.js
  @@ -574,7 +574,7 @@ var Parser = /** @class */ (function () {
               }
               var functionStatement = _this.getFunctionStatement(statement);
               // Extracting default values from props destructuring
  -            if (functionStatement && functionStatement.parameters.length) {
  +            if (functionStatement && functionStatement.parameters && functionStatement.parameters.length) {
                   var name = functionStatement.parameters[0].name;
                   if (ts.isObjectBindingPattern(name)) {
                       return __assign({}, res, _this.getPropMap(name.elements));

I've made a PR in react-docgen-typescript to solve the issue

@hazem3500
Copy link
Author

Closed as PR is merged in react-docgen-typescript

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

2 participants