better-docs icon indicating copy to clipboard operation
better-docs copied to clipboard

Error building with component containing optional chaining

Open DavidBriglio opened this issue 4 years ago • 9 comments

This may not be strictly related to this library and may just be a dependency issue, but when I try to use the @component tag on a react component that contains optional chaining, I get an error about ChainExpression:

Test react file to be processed:

import React from 'react';

/**
 * @component
 */
const TestComponent = ({ test }) => <div>{test?.x ? 'Test1' : 'Test2'}</div>;

export default TestComponent;

jsdoc.json:

{
  "opts": {
    "template": "node_modules/better-docs",
    "destination": "docs",
    "recurse": true
  },
  "source": {
    "include": ["dev_test"]
  },
  "tags": {
    "allowUnknownTags": ["category", "subcategory", "component"]
  },
  "plugins": ["node_modules/better-docs/category", "node_modules/better-docs/component"]
}

Error from running jsdoc -c jsdoc.json:

C:\...\project\node_modules\better-docs\component.js:67
      throw error
      ^

Error: did not recognize object of type "ChainExpression"
    at Object.getFieldNames (C:\...\project\node_modules\ast-types\lib\types.js:661:19)
    at visitChildren (C:\...\project\node_modules\ast-types\lib\path-visitor.js:185:36)
    ...

After trying to track down where this issue was coming from I stumbled onto this: https://github.com/benjamn/ast-types/issues/383

Maybe this library would need to update its dependency on @babel/core to a newer version?

DavidBriglio avatar Oct 02 '20 20:10 DavidBriglio

it shouldnt be a problem. try to remove your node_modules and install them again. the same with parcel-bundler

wojtek-krysiak avatar Oct 05 '20 03:10 wojtek-krysiak

I have tried doing as you suggested:

  • Removed package-lock.json
  • Removed and reinstalled node_modules
  • Removed and reinstalled parcel-bundler

But I am still getting the same error.

DavidBriglio avatar Oct 05 '20 13:10 DavidBriglio

I now see that the error is in js file (not ts) (ast-types\lib\types.js) - so typescript is not handling them. I thin you have to bump up your node version.

wojtek-krysiak avatar Oct 06 '20 04:10 wojtek-krysiak

I have updated my node version to v12.18.4 but I am still experiencing the same issue. Thank you for your help by the way!

DavidBriglio avatar Oct 09 '20 19:10 DavidBriglio

i think that reactDocgen will have to be updated. It throws an error. And i dont use it since i am working mostly with typescript. I am just thinking: can you update it on your local version and see if that hepls?

wojtek-krysiak avatar Oct 11 '20 12:10 wojtek-krysiak

If I install react-docgen directly from the git master branch, this issue is resolved. The dependency in this package should be updated when the next react-docgen version is released. Thanks again for your help 😄

DavidBriglio avatar Oct 13 '20 12:10 DavidBriglio

Same error, will try to explicitly define react-docgen dependency but commenting here to bump up the issue.

deepankarmalhan avatar Mar 30 '21 16:03 deepankarmalhan

Wiped and redownloaded npm_modules after adding react-docgen: ^4.1.1 as a dev dependency. Still facing the error. @DavidBriglio what version of the library did you end up using to resolve the issue?

deepankarmalhan avatar Mar 30 '21 16:03 deepankarmalhan

@deepankarmalhan I just used the command npm install https://github.com/reactjs/react-docgen.git at the time, which I believe would have been between version 5.3.0 and 5.3.1.

DavidBriglio avatar Apr 01 '21 14:04 DavidBriglio