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

Error building with component containing optional chaining #106

Open
DavidBriglio opened this issue Oct 2, 2020 · 9 comments
Open

Error building with component containing optional chaining #106

DavidBriglio opened this issue Oct 2, 2020 · 9 comments

Comments

@DavidBriglio
Copy link

DavidBriglio commented Oct 2, 2020

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:
benjamn/ast-types#383

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

@wojtek-krysiak
Copy link
Contributor

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

@DavidBriglio
Copy link
Author

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.

@wojtek-krysiak
Copy link
Contributor

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.

@DavidBriglio
Copy link
Author

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!

@wojtek-krysiak
Copy link
Contributor

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?

@DavidBriglio
Copy link
Author

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 😄

@deepankarmalhan
Copy link

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

@deepankarmalhan
Copy link

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?

@DavidBriglio
Copy link
Author

@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.

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

No branches or pull requests

3 participants