Skip to content

TypeError: Cannot read property 'filter' of undefined #213

@unzico

Description

@unzico

Hi there,

thanks for your work on this project! I'm currently using it in a Storybook project and have encountered the following error.

Stack trace

ERROR in ./src/components/Checkbox/utils/fireCallbackOnEnterKey.ts
Module build failed (from D:/01 Privat/Programmieren/club of code/clubofcode-app/node_modules/react-docgen-typescript-loader/dist/index.js):
TypeError: Cannot read property 'filter' of undefined
    at getTextValueOfClassMember (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:571:10)
    at computeComponentName (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:614:9)
    at Parser.getComponentInfo (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:124:52)
    at D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:701:27
    at Array.map (<anonymous>)
    at D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:700:14
    at Array.reduce (<anonymous>)
    at parseWithProgramProvider (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:693:10)
    at Object.parseWithProgramProvider (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript\lib\parser.js:74:2
0)
    at processResource (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript-loader\dist\loader.js:113:32)
    at Object.loader (D:\01 Privat\Programmieren\club of code\clubofcode-app\node_modules\react-docgen-typescript-loader\dist\loader.js:51:25)
 @ ./src/components/Checkbox/Checkbox.tsx 4:0-72 8:139-161
 @ ./src/components/Checkbox/stories/Checkbox.stories.tsx
 @ ./src/components sync \.stories\.tsx?$
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/con
fig.js D:/01 Privat/Programmieren/club of code/clubofcode-app/node_modules/webpack-hot-middleware/client.js?reload=true&quiet=true

I was able to track it down to the following line

const [textValue] = classDeclaration.members

The issue is resolved when changing

const [textValue] = classDeclaration.members.filter([...]

to

const [textValue] = classDeclaration.members && classDeclaration.members.filter([...]

Additional notice
The function (namely fireCallbackOnEnterKey) producing this error is a simple utility function used inside a React functional component.

This issue may be related to the following issues
strothj/react-docgen-typescript-loader#11
#191
#195

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions