You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
at computeLineStarts (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:9441:27)
at Object.getLineStarts (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:9501:60)
at getCurrentLineMap (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:100407:59)
at emitDetachedCommentsAndUpdateCommentsInfo (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:104074:94)
at emitBodyWithDetachedComments (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:103923:17)
at emitSourceFile (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:102638:21)
at pipelineEmitWithHint (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:100488:24)
at pipelineEmit (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:100440:13)
at print (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:100374:13)
at Object.writeFile (node_modules\.pnpm\[email protected]\node_modules\typescript\lib\typescript.js:100358:13)
项目改为monorepo结构后,在进行类型检查的时候typescript抛出
解决方案:
避免不同工作空间引用同一个工作空间
以这个项目为例
本身是一个后台管理系统,通过subtree引入了两个包,分别是dynamic-form和basic-components
dynamic-form和basic-components本身也是monorepo,有自己的工作空间
结构本身没什么问题,理论上website用到的组件都是通过basic-components导出后的,但是有的地方会用到basic-components的组件的类型声明,比如
@basic-components/components/search/type
,而basic-components本身并没有导出组件对应的类型声明,因此为了满足类型检查的条件,需要在website中引入@basic-components/components
\website + \@basic-components/components \packages \dynamic-form \basic-components \@basic-components/components
这样就会遇到上面类型检查找不到文件的问题
对于这种不同工作空间引入的包名相同的,可以直接外部根目录引入
===================================================================================
定位了一下抛出问题的地方
翻了一下github,也有不少人遇到了类似的问题,大概看了一下,出现问题的原因好像是因为不同工作空间引入了同一个或名称相同的依赖包,简单的说就是package.json的name相同。
导致做类型检查读取文件的时候会重定向到同一个目录里,但是实际上由于工作空间的存在,实际路径是对不上的,导致读取不到文件内容。
https://github.com/microsoft/TypeScript/issues/41717#issuecomment-781128223
但是如果引用的是第三方依赖,比如从npm下载的,不知道会不会出现这个问题。话又说回来,正常的第三方依赖一般都是编译后甚至是压缩过的,不太会出现。因为这个问题本质是typescript找不到需要进行类型检查的问题,而从一开始就引用js文件自然就不需要进行类型查检了。
这么一想的话,难怪issues里有人提出来
tsconfig.js
中allowJs
关闭后就解决了这个问题,可能也是这个原因,没有从根本上解决,只是跳过这检查。最后吐槽一下官方,这个bug的修复版本从4.2.1改再改,4.3.1的时候被标注允许修复,结果又跳票到4.5。
The text was updated successfully, but these errors were encountered: