Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`

错误信息:

/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:43192
        ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "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.");
                 ^
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.
    at Object.resolveTypeReferenceDirective (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:43192:18)
    at /usr/src/node_modules/.pnpm/ts-node@9.1.1_typescript@4.8.3/node_modules/ts-node/src/index.ts:623:55
    at Array.map (<anonymous>)
    at Object.resolveTypeReferenceDirectives (/usr/src/node_modules/.pnpm/ts-node@9.1.1_typescript@4.8.3/node_modules/ts-node/src/index.ts:622:33)
    at actualResolveTypeReferenceDirectiveNamesWorker (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:118249:163)
    at resolveTypeReferenceDirectiveNamesWorker (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:118549:26)
    at processTypeReferenceDirectives (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:120046:31)
    at findSourceFileWorker (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:119931:21)
    at findSourceFile (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:119783:26)
    at processImportedModules (/usr/src/node_modules/.pnpm/typescript@4.8.3/node_modules/typescript/lib/typescript.js:120192:25)

原因,typescript版本过高。
由于最近添加了新包,所以在重新构建时,typescript被重新安装了,正好typesrcipt发布了最新的4.8.3版本,所以根据我们项目的版本适配规则,typescript是最新的4.8.3版本,但是其它依赖typescript的却没有适配这个版本,所以造成构建失败,因此需要重新修改typescript的版本;

 

修改方案:

1、typescript

# 修改之前
“typescript”:^4.2.3

# 修改后
“typescript”:~4.2.3

2、其它依赖:

例如ts-loader,它也会依赖typescript,这个包内package.json中devDependencies可能会有typescript依赖,也会产生影响;
就是如果typescript版本是^4.2.3这种方式,那么也会安装最新的4.8.3版本,所以要给ts-loader适当降低版本,或者选择对typescript依赖不是^4.2.3这种版本号的方式!

 

^ 与 ~ 的区别:
~4.2.3,更新的版本号是4.2.x,但不会安装4.3.0+的版本版本
^4.2.3,更新的版本号是4.x.x,但不会安装5.0.0及以上的版本

 

posted @ 2022-09-22 14:46  keRee  阅读(5271)  评论(0编辑  收藏  举报