4.2.x: ESM build cannot be loaded by Node (imports without `.js`)

未关闭 适合新手
#730 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
85/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

检查 esm/ 下的相对导入,从 esm/index.nohighlight.js、esm/Editor.nohighlight.js、esm/Editor.common.js 和 esm/components/TextArea/*.common.js 中的示例开始。检查生成的 ESM 文件是否存在没有扩展名的相对导入,然后使用提供的 Node 导入命令复现。完成标准是 esm/ 中的每个相对导入都以 .js 结尾,并且 package 能在 Node 中加载。

由索引模型根据 Issue 内容生成。

描述

Since 4.2.0, esm/package.json sets "type": "module", but some relative imports in esm/ still have no .js extension. Node refuses them, so loading the package fails outside a bundler (Vitest, SSR). Bundlers such as Vite still work.

The imports without .js are the ones whose file name has a dot, for example:

  • esm/index.nohighlight.js: import MDEditor from './Editor.nohighlight';
  • esm/Editor.nohighlight.js: import { createMDEditor } from './Editor.factory';
  • esm/Editor.common.js, esm/components/TextArea/*.common.js: same pattern

Repro (Node 24, @uiw/[email protected]):

npm i @uiw/[email protected] react react-dom
node -e "import('@uiw/react-md-editor/nohighlight')"
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/@uiw/react-md-editor/esm/Editor.nohighlight' imported from .../node_modules/@uiw/react-md-editor/esm/index.nohighlight.js

4.1.6 loads fine: there is no esm/package.json, so the files are not read as strict ES modules.

Expected: every relative import in esm/ ends with .js.

主要语言
TypeScript
星标
2.9k
派生
200
平均合并
6 小时 38 分钟
30 天内合并 PR
16

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uiwjs/react-md-editor 的其他 Issue

查看 uiwjs/react-md-editor 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。