VS Code 和 Yarn PnP
Posted
技术标签:
【中文标题】VS Code 和 Yarn PnP【英文标题】:VS Code and Yarn PnP 【发布时间】:2022-01-02 00:46:43 【问题描述】:yarn pnp sdk 和 typescript 有什么不兼容的地方吗?我已经通过yarn sdks
安装了 sdk,在 TS 服务器日志中它似乎是从缓存中提取的(例如:)
/osi/disp/vob/web/.yarn/cache/typescript-patch-04b86b0e5c-24a439e062.zip/node_modules/typescript/lib/lib.es5.d.ts
然而 VS Code 找不到模块:
Cannot find module 'react' or its corresponding type declarations.
它通过 webpack 构建和运行。这似乎是一个 VS Code/sdk 工件。
试图追踪反应解决有一些奇怪的笔记:
Info 1216 [08:36:07.761] DirectoryWatcher:: Added:: WatchInfo: /osi/disp/vob/web/react 1 undefined Project: /osi/disp/vob/web/tsconfig.json WatchType: Failed Lookup Locations
Info 1217 [08:36:07.761] Elapsed:: 0.06486300379037857ms DirectoryWatcher:: Added:: WatchInfo: /osi/disp/vob/web/react 1 undefined Project: /osi/disp/vob/web/tsconfig.json WatchType: Failed Lookup Locations
那些文件夹不存在,似乎它可能将'react'
解释为'./react'
tsconfig:
"compilerOptions":
"baseUrl": "./",
"target": "es5",
"lib": [
"es6",
"dom",
"es2016",
"es2017"
],
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"declaration": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"jsx": "react",
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": true,
"resolveJsonModule": true,
"skipLibCheck": true
简单的复制: https://github.com/rcketscientist/vs-code-pnp-test
感谢任何见解或指示以进一步调查。
【问题讨论】:
【参考方案1】:SDK 目前与 TS 4.5 不兼容:
https://github.com/yarnpkg/berry/issues/3722
降级到 4.4.4 修复它:
-
纱线删除打字稿
rm -rf .yarn/sdks/typescript
yarn add -D typescript@4.4.4
yarn dlx @yarnpkg/sdks 基础
【讨论】:
以上是关于VS Code 和 Yarn PnP的主要内容,如果未能解决你的问题,请参考以下文章
VS code上跑yarn start报running scripts is disabled on this system错误的解决方法
VS code上跑yarn start报running scripts is disabled on this system错误的解决方法
VS code上跑yarn start报running scripts is disabled on this system错误的解决方法