Skip to content

fix(web): replace fs.cpSync to avoid Windows crash in extract step - #574

Open
chx7776-afk wants to merge 1 commit into
shareAI-lab:mainfrom
chx7776-afk:fix/web-extract-cpsync-windows-crash
Open

chx7776-afk wants to merge 1 commit into
shareAI-lab:mainfrom
chx7776-afk:fix/web-extract-cpsync-windows-crash

Conversation

@chx7776-afk

@chx7776-afk chx7776-afk commented Sep 14, 2026

Copy link
Copy Markdown

Summary

Replaces the single fs.cpSync call in web/scripts/extract-content.ts with a small recursive copy helper.

Closes #573.

Why

On Windows with Node 22, fs.cpSync kills the process at the native layer with STATUS_STACK_BUFFER_OVERRUN (exit code 0xC0000409) and no JS-level error:

> web@0.1.0 extract
> tsx scripts/extract-content.ts

Extracting course content...
  Repo root: <repo root>
  Source: root chapter folders (17)

...then the process is gone. Because this script backs the predev hook, npm run dev never starts either.

The crash is not specific to this repo — copying a directory holding a single one-line text file is enough to trigger it, so there is no project-side workaround other than not calling fs.cpSync.

Change

fs.cpSync is used in exactly one place, copyChapterAssets(). The new copyDirRecursive() helper does the same thing via fs.readdirSync with withFileTypes + fs.mkdirSync + fs.copyFileSync, and recurses into subdirectories. path is already imported in this file.

No behaviour change on other platforms: same files land in the same destination layout.

Verification

Windows 11, Node v22.20.0, run against a clean tree (removed web/public/course-assets/ first):

before after
exit code 3221226505 (0xC0000409) 0
extraction output aborted after Source: root chapter folders (17) 17 versions / 16 diffs / 51 docs
web/public/course-assets/ not written 74 files written

Also confirmed npm run build proceeds past the previously blocking predev step.

Notes

  • One file touched, web/scripts/extract-content.ts: +21 / -1.
  • No changes to chapter code or READMEs, so the three-language sync rule does not apply here.
  • Opened with AI assistance for reproduction and drafting; I ran the before/after on my own machine and stand behind the change.
中文说明(Chinese summary)

摘要

web/scripts/extract-content.ts 中唯一一处 fs.cpSync 调用替换为一个小型递归复制函数。

关联 Issue:#573

背景

在 Windows + Node 22 下,fs.cpSync 会在原生层直接终止进程,报 STATUS_STACK_BUFFER_OVERRUN(退出码 0xC0000409),且没有任何 JS 层报错

> web@0.1.0 extract
> tsx scripts/extract-content.ts

Extracting course content...
  Repo root: <仓库根目录>
  Source: root chapter folders (17)

然后就没了下文。由于该脚本是 predev 钩子的实现,npm run dev 也随之无法启动。

这个崩溃与仓库本身无关 —— 即使只复制一个含单行文本文件的目录也照样触发,因此项目侧除了「不要调用 fs.cpSync」之外没有别的绕法。

改动

fs.cpSync 全仓库只用在一处,即 copyChapterAssets()。新增的 copyDirRecursive()fs.readdirSync(带 withFileTypes)+ fs.mkdirSync + fs.copyFileSync 实现相同效果,并递归处理子目录。path 在该文件中已有引入。

其他平台行为不变:同样的文件落到同样的目标目录结构下。

验证

环境 Windows 11 + Node v22.20.0,在干净的工作区上运行(先删掉 web/public/course-assets/):

修复前 修复后
退出码 32212265050xC0000409 0
提取输出 停在 Source: root chapter folders (17) 17 versions / 16 diffs / 51 docs
web/public/course-assets/ 未生成 生成 74 个文件

同时确认 npm run build 能够越过此前阻塞它的 predev 步骤继续执行。

说明

  • 仅改动一个文件 web/scripts/extract-content.ts:+21 / -1。
  • 未改动任何章节代码或 README,因此不涉及三语同步规则。
  • 本次修改借助 AI 完成复现与草拟;修复前后的对比由我本人在本机实测,并认可该改动。

`fs.cpSync` in `copyChapterAssets` terminates the Node process on Windows
with Node 22. Running `npm run extract` (the `predev` hook of `npm run dev`)
prints "Source: root chapter folders (17)" and then exits with
STATUS_STACK_BUFFER_OVERRUN (exit code 0xC0000409) without any JS-level
error, so the course data is never written and the dev server never starts.

Replace it with a small recursive copy helper built on `fs.readdirSync` +
`fs.copyFileSync`, which is what `fs.cpSync` does internally minus the
native path that crashes here.

Verified on Windows 11 / Node v22.20.0:
- before: exit 0xC0000409, extraction aborted, no course-assets output
- after:  exit 0, "17 versions / 16 diffs / 51 docs", 74 asset files written
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

Successfully merging this pull request may close these issues.

[Bug] extract-content.ts crashes on Windows: fs.cpSync aborts tsx with 0xC0000409

1 participant