[Bug] extract-content.ts crashes on Windows: fs.cpSync aborts tsx with 0xC0000409
Problem
npm run dev in web/ never starts on Windows. The predev hook runs npm run extract, which uses tsx scripts/extract-content.ts. That script aborts partway through:
> [email protected] extract
> tsx scripts/extract-content.ts
Extracting course content...
Repo root: <repo root>
Source: root chapter folders (17)
...and then the process dies. No stack trace, no error message — just the shell prompt coming back with a non-zero exit code.
Root cause
copyChapterAssets() calls fs.cpSync(imagesDir, outDir, { recursive: true }):
https://github.com/shareAI-lab/learn-claude-code/blob/main/web/scripts/extract-content.ts#L218
On Windows with Node 22, fs.cpSync terminates the process at the native layer:
| Exit code | 3221226505 / 0xC0000409 (STATUS_STACK_BUFFER_OVERRUN) |
| JS exception | none — the process is killed before JS can catch anything |
Because the failure is native, there is no stack trace to follow. This is why it looks like the script "hangs after Source: root chapter folders (17)".
Minimal reproduction
Reproducible outside this repo — copying a directory that contains a single one-line text file is enough:
const fs = require("fs");
fs.mkdirSync("src", { recursive: true });
fs.writeFileSync("src/a.txt", "x");
fs.cpSync("src", "dst", { recursive: true }); // process dies, exit 0xC0000409
$ node repro.js
$ echo $?
3221226505
Environment
| OS | Windows 11 |
| Node | v22.20.0 |
| npm | (bundled with Node 22) |
Impact
The extraction produces no web/public/course-assets/ output and no generated course data, so the web/ app cannot be built or run locally on Windows.
Possible fix
fs.cpSync is only used in this one place. Replacing it with a small recursive copy helper (fs.readdirSync + fs.mkdirSync + fs.copyFileSync) avoids the crashing native code path and keeps the behaviour identical:
before: exit 0xC0000409, extraction aborted, no course-assets output
after: exit 0, "17 versions / 16 diffs / 51 docs", 74 asset files written
I have a patch ready and will open a PR that references this issue.
Note: opened with AI assistance for research/reproduction; I ran the reproduction and the fix on my own machine and stand behind the report.
中文说明(Chinese summary)问题
在 Windows 上,web/ 下的 npm run dev 永远起不来。它的 predev 钩子会执行 npm run extract,也就是 tsx scripts/extract-content.ts。该脚本跑到一半就中断:
> [email protected] extract
> tsx scripts/extract-content.ts
Extracting course content...
Repo root: <仓库根目录>
Source: root chapter folders (17)
然后就没了 —— 没有堆栈、没有报错信息,只是 shell 提示符回来了,退出码非零。
根因
copyChapterAssets() 中调用了 fs.cpSync(imagesDir, outDir, { recursive: true }):
https://github.com/shareAI-lab/learn-claude-code/blob/main/web/scripts/extract-content.ts#L218
在 Windows + Node 22 下,fs.cpSync 会在原生层终止进程:
| 退出码 | 3221226505 / 0xC0000409(STATUS_STACK_BUFFER_OVERRUN) |
| JS 异常 | 无 —— 进程在 JS 能捕获任何东西之前就被杀掉了 |
正因为是原生层崩溃,所以没有任何堆栈可跟。这也是它看起来像「卡在 Source: root chapter folders (17)」的原因。
最小复现
脱离本仓库也能复现 —— 复制一个只含单行文本文件的目录就够了:
const fs = require("fs");
fs.mkdirSync("src", { recursive: true });
fs.writeFileSync("src/a.txt", "x");
fs.cpSync("src", "dst", { recursive: true }); // 进程死亡,退出码 0xC0000409
$ node repro.js
$ echo $?
3221226505
环境
| 操作系统 | Windows 11 |
| Node | v22.20.0 |
影响
提取过程不会生成任何 web/public/course-assets/ 产物,也不会生成课程数据,导致 web/ 应用在 Windows 上无法本地构建或运行。
可能的修复
fs.cpSync 全仓库只用了这一处。换成一个小型递归复制函数(fs.readdirSync + fs.mkdirSync + fs.copyFileSync)即可绕开会崩溃的原生代码路径,行为保持一致:
修复前:退出码 0xC0000409,提取中断,无 course-assets 产物
修复后:退出码 0,17 versions / 16 diffs / 51 docs,生成 74 个 asset 文件
补丁已就绪,我会开一个关联本 issue 的 PR。
说明:本 issue 借助 AI 完成调研与复现;复现过程与修复均由我本人在本机跑通,并认可该报告。
Source: shareAI-lab/learn-claude-code