【问题标题】:VS Code and Yarn PnPVS Code 和 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

感谢任何见解或指示以进一步调查。

【问题讨论】:

    标签: typescript visual-studio-code yarnpkg yarnpkg-v3


    【解决方案1】:

    SDK 目前与 TS 4.5 不兼容:

    https://github.com/yarnpkg/berry/issues/3722

    降级到 4.4.4 修复它:

    1. 纱线删除打字稿
    2. rm -rf .yarn/sdks/typescript
    3. yarn add -D typescript@4.4.4
    4. yarn dlx @yarnpkg/sdks 基础

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 2020-05-17
      • 2021-10-30
      • 2020-06-25
      • 2021-02-15
      • 2021-12-04
      • 2019-07-24
      • 2022-12-02
      • 1970-01-01
      相关资源
      最近更新 更多