React项目升级npm包至v4.7.2后遇TypeScript内部错误求助
问题
React应用升级npm包至v4.7.2后,执行npm start触发TypeScript内部错误:
INTERNAL ERROR(undefined,undefined) Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself. stack trace: Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.
已尝试以下方案但未解决:
- 执行
npm install typescript@latest ts-node@latest - 将TypeScript从4.7.4降级至4.4.0
- 删除
node_modules和lock文件后重新安装依赖
解决方法
这个错误核心是有依赖包使用了过时的resolveTypeReferenceDirectives签名,并非TypeScript本身问题,可按以下步骤排查:
锁定TypeScript版本并排查冲突依赖
- 在
package.json中明确指定与npm包版本匹配的TypeScript版本:"typescript": "~4.7.2" - 执行
npm ls typescript查看项目中所有依赖的TypeScript版本,找出版本冲突的包,重点检查ts-loader、fork-ts-checker-webpack-plugin这类直接调用TS API的工具包。
- 在
升级兼容的工具包版本
- 若使用
ts-loader,升级到9.3.x及以上版本,确保与TypeScript 4.7.x兼容 - 若使用
fork-ts-checker-webpack-plugin,升级到7.2.x及以上版本,该版本修复了与TS 4.7.x的API兼容问题
- 若使用
检查
tsconfig.json配置- 确认
compilerOptions中typeRoots或types字段配置正确,避免传递非字符串值给类型解析指令 - 若
tsconfig.json中有自定义resolveTypeReferenceDirectives配置,尝试移除后重新启动项目
- 确认
清理缓存后重装依赖
- 执行
npm cache clean --force清除npm缓存,再重新执行npm install
- 执行
内容的提问来源于stack exchange,提问作者Goutham J.M
相关产品推荐
相关产品推荐

