使用 @component 生成 React 18 项目的 JSDoc 文档

问题描述 投票:0回答:1

我正在尝试使用

better-docs
为 React 18 项目设置 JSDoc,以便我可以使用 @component 装饰器来记录我的组件。

当我尝试安装 better-docs 时,出现以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^18.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.2" from [email protected]

有人遇到过这个问题吗?有没有办法让 JSDoc 与 React 18 一起工作?我真的不想仅仅为了处理文档而降级 React 版本。如果没有办法解决这个问题,我可以使用更好的文档生成包吗?

在 package.json 中,我将文档脚本定义为

"docs": "jsdoc -c jsdoc.conf.json

这是我的 jsdoc.conf.json:

{
    "tags": {
        "allowUnknownTags": true,
        "dictionaries": ["jsdoc"]
    },
    "plugins": [
        "plugins/markdown",
        "node_modules/better-docs/typescript",
        "node_modules/better-docs/component"
    ],
    "opts": {
        "destination": "spec/docs",
        "encoding": "utf8",
        "readme": "README.md",
        "recurse": true,
        "verbose": true,
        "template": "./node_modules/better-docs"
    },
    "source": {
        "include": [ "./src" ],
        "exclude": [ "./src/**/*.text,tsx", "./src/**/*.test.ts" ],
        "includePattern": "\\.(jsx|js|ts|tsx)$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "templates": {
        "cleverLinks": false,
        "monospaceLinks": false,
        "search": true,
        "better-docs": {
            "name": "framework documentation",
            "title": "Framework Documentation",
            "hideGenerator": false,
            "navLinks": [
                {
                    "label": "Respository",
                    "href": "..."
                }
            ]
        }
    }
}

如上所述,我尝试使用

better-docs
选项安装
--legacy-peer-deps
。当我运行
npm run docs
时,没有生成文件生成到>spec 中,也没有生成entry.js 文件。我可以通过从浏览器查看 global.html 文件来查看文档,但任何带有
@component
装饰器的文件都不会显示在任何地方。

output and result

reactjs jsdoc
1个回答
2
投票

快跑吧

npm install --legacy-peer-deps

你有一个问题,你的 React 18 太新了,更好的文档仍然依赖于 React 17

© www.soinside.com 2019 - 2024. All rights reserved.