Skip to content

[Bug]: 开启 Rspress Module Doc 功能,代码块设置 iframe,报 Can't resolve 'react/jsx-dev-runtime' #6060

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

Closed
BeaconSage opened this issue Aug 9, 2024 · 2 comments
Labels
💉 bug Something isn't working Modern.js Module

Comments

@BeaconSage
Copy link

版本信息

System:
    OS: Linux 6.8 Ubuntu 24.04 LTS 24.04 LTS (Noble Numbat)
    CPU: (8) x64 AMD Ryzen 7 5825U with Radeon Graphics
    Memory: 8.12 GB / 15.62 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  npmPackages:
    @modern-js/eslint-config: 2.58.0 => 2.58.0 
    @modern-js/module-tools: 2.58.0 => 2.58.0 
    @modern-js/plugin-rspress: 1.27.1 => 1.27.1 
    @modern-js/plugin-tailwindcss: 2.58.0 => 2.58.0

问题详情

初始化项目, 开启 Rspress Module Doc 功能,在 doc/index.mdx 中 输入代码块,并设置类型为 iframepnpm dev 后报 Can't resolve 'react/jsx-dev-runtime'
截屏2024-08-10 00 33 29

demo:
test.tar.gz

复现链接

附件 test.tar.gz

复现步骤

  1. pnpm dev
  2. 控制台报错
File: /home/beacon/Documents/test/node_modules/.rspress/virtual-demo/_index_1.entry.tsx:1:1
  × Module not found: Can't resolve 'react/jsx-dev-runtime' in '/home/beacon/Documents/test/node_modules/.rspress/virtual-demo'
   ╭─[1:34]
 1 │ import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
   ·                                   ───────────────────────
 2 │ import { render } from 'react-dom';
 3 │ import "/home/beacon/Documents/test/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__react-_yafijyfmxaorishhjxftxnjjba/node_modules/@rspress/plugin-preview/static/global-styles/entry.css";
   ╰────
@BeaconSage BeaconSage added the 💉 bug Something isn't working label Aug 9, 2024
@zllkjc
Copy link
Member

zllkjc commented May 29, 2025

因为很久没有人关注这个问题。我尝试回答一下。

Module Tools 目前已经逐步升级到 rslib https://lib.rsbuild.dev/zh/guide/start/,后续模块文档功能 rspress 将会以更加轻量耦合的方式提供给 rslib。

这个 issue 中主要的问题是因为项目中没有 react 依赖,这可能和创建的时候选择的类型有关(Node.js 项目、React 库项目等)。我想你可以直接安装 react 依赖来解决这个问题。

@zllkjc zllkjc closed this as completed May 29, 2025
@zllkjc
Copy link
Member

zllkjc commented May 29, 2025

因为后续 Modern.js Module 将转移到 rslib 中,推荐在 rslib 仓库中提 issue~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💉 bug Something isn't working Modern.js Module
Projects
None yet
Development

No branches or pull requests

2 participants