better-docs
better-docs copied to clipboard
Error building with component containing optional chaining
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?
it shouldnt be a problem. try to remove your node_modules and install them again. the same with parcel-bundler
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.
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.
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!
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?
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 😄
Same error, will try to explicitly define react-docgen
dependency but commenting here to bump up the issue.
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 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.