DSH 0.1.6-alpha profile 模块解析缺陷:require('包名/') 触发 resolve.paths 崩溃 #7377
ShiraKawaYZK
started this conversation in
General
Replies: 1 comment
|
补充一个更新版本上的复现:0.2.0-rc.2(当前最新 prerelease,桌面版)仍受影响 环境:Windows 11 x64; 触发:首次调用插件的 插件侧内置的诊断把它归因到 同一插件同一环境下不受影响的路径(都已实测通过): 结论:主贴建议的两处改动(① 切掉子路径后重新判内建名;② 另外一点观察:这个报错在插件侧会被二次包装成「缺少依赖 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
DSH 0.1.6-alpha profile 模块解析缺陷:require('包名/') 触发 resolve.paths 崩溃
环境
@deepseek-ai/dsh0.1.6-alpha.2(npmlatest是 0.1.5-rc.2,即升级前版本)@deepseek-ai/dsh-app-boot0.1.6-alpha.2webdsh-office-toolkit0.3.28(第三方插件,未做任何修改)现象
从 0.1.5-rc.2 升级到 0.1.6-alpha.2 之后,任何懒加载 ExcelJS 的插件工具都会失败,报错原文是
createRequire.resolve.paths is not a function or its return value is not iterable。同一个插件在纯 Node 进程里直接调用自身核心函数(
opRead()读同一个.xlsx)完全正常,只在 DSH 进程内失败,说明问题在宿主侧的模块解析。插件侧还会把它二次误报成缺少依赖,掩盖真实原因:
缺少依赖 process/(用于:Excel 读写) ... 原始报错: Cannot find module 'process/'。最小复现
纯 Node 下
require.resolve('process/')会正常解析到 npm polyfill 包node_modules/process/index.js。readable-stream正是刻意用这个尾斜杠写法(require('process/')、require('string_decoder/'))来强制走 polyfill 而不是内建。根因(源码位置)
文件:
packages/boot/app-boot/src/profile-resolution/resolver.tsbarePackageName():isBuiltin(request)只判断了原始请求,切掉子路径之后没有重新判断,于是'process/'被归约成'process',也就是一个内建名。resolve.paths调用(约 L165、L350):as string[]只是类型断言,运行时没有兜底;resolve.paths()对内建名返回null,for...of null直接抛 TypeError。同一个文件里
packageDirFromAnchor写的是... ?? [],说明作者本意就是要防这种情况,只是这两处漏了。建议改动
影响面
任何依赖树里出现「内建名 + 子路径」这种 polyfill 写法的插件都会中招。
readable-stream极为常见,其下游包括exceljs、@wekanteam/exceljs、jszip、unzipper、archiver、duplexer2、lazystream等。回归说明
标签
dsh-v0.1.5-rc.2下packages/boot/app-boot/src/只有index.ts与profile.ts,不存在profile-resolution/目录。该模块解析子系统是 0.1.6-alpha 新引入的,因此这是新引入的回归,而不是老问题。临时绕行(用户侧)
在本机的
lib/index.js与lib/worker/profile-resolution-bootstrap.js两个构建产物上打同等补丁即可恢复;DSH 升级后会覆盖,需要重打。English summary
Upgrading DSH from 0.1.5-rc.2 to 0.1.6-alpha.2 broke any plugin tool that lazily imports ExcelJS, failing with
createRequire.resolve.paths is not a function or its return value is not iterable.Root cause is in the new profile module resolver, file
packages/boot/app-boot/src/profile-resolution/resolver.ts:barePackageName()does not re-checkisBuiltin()after stripping the subpath, so'process/'is reduced to the builtin name'process'.createRequire(parent).resolve.paths(name) as string[]with no runtime guard;require.resolve.paths()returnsnullfor builtin names, andfor...of nullthrows.The
'process/'and'string_decoder/'specifiers come fromreadable-stream, which deliberately uses the trailing slash to force the npm polyfill package over the builtin. Plain Node resolves'process/'tonode_modules/process/index.jswithout issue.Suggested fix: re-check
isBuiltin(bare)after slicing, and use?? []at both call sites (the same file already does this inpackageDirFromAnchor). The resolver subsystem is absent from tagdsh-v0.1.5-rc.2, so this is a fresh regression introduced in 0.1.6-alpha.All reactions