typescript 找不到带有coc-tsserver的模块(ts 2307)

zbdgwd5y  于 2023-04-13  发布在  TypeScript
关注(0)|答案(1)|浏览(163)

我正在使用NeoVim和CoC进行支持yarn-3 pnp的项目的TS开发。在某个时候,编辑器停止看到导入,并开始抱怨导入的模块不存在。(见截图)。我已经为vim配置了SDK,并安装了ts sdks,更新了yarn并重新启动了编辑器。以下是一些细节:OS:

  1. DISTRIB_ID=Ubuntu
  2. DISTRIB_RELEASE=22.04
  3. DISTRIB_CODENAME=jammy
  4. DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"

Neovim:

  1. NVIM v0.7.2
  2. Build type: Release
  3. LuaJIT 2.1.0-beta3
  4. Compiled by team+vim@tracker.debian.org

package.json:

  1. {
  2. "private": true,
  3. ...
  4. "devDependencies": {
  5. "typescript": "4.5.5",
  6. },
  7. "packageManager": "yarn@3.5.0"
  8. }

.yarnrc.yml

  1. checksumBehavior: update
  2. nodeLinker: pnp
  3. plugins:
  4. - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
  5. spec: "@yarnpkg/plugin-workspace-tools"
  6. - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
  7. spec: "@yarnpkg/plugin-typescript"
  8. yarnPath: .yarn/releases/yarn-3.5.0.cjs

tsconfig.json:

  1. {
  2. "compilerOptions": {
  3. "outDir": "./dist/",
  4. "noImplicitAny": true,
  5. "skipLibCheck": true,
  6. "module": "es6",
  7. "target": "es6",
  8. "jsx": "react",
  9. "allowJs": true,
  10. "moduleResolution": "node",
  11. "resolveJsonModule": true,
  12. "allowSyntheticDefaultImports": true,
  13. "paths": {
  14. "@company/xxx-rqb": ["./packages/xxx-rqb/src"]
  15. }
  16. },
  17. "exclude": ["**/*.test.ts", "**/*.spec.ts"]
  18. }

.vim/coc-settings.json:

  1. {
  2. "eslint.packageManager": "yarn",
  3. "eslint.nodePath": ".yarn/sdks",
  4. "workspace.workspaceFolderCheckCwd": false,
  5. "tsserver.tsdk": ".yarn/sdks/typescript/lib"
  6. }

CocInfo:

  1. ## versions
  2. vim version: NVIM v0.7.2
  3. node version: v16.15.1
  4. coc.nvim version: 0.0.82-b7375d5f 2023-01-30 05:09:03 +0800
  5. coc.nvim directory: /home/user/.nvim/plugin/coc.nvim
  6. term: tmux
  7. platform: linux
  8. ## Log of coc.nvim
  9. 2023-04-11T18:17:33.885 INFO (pid:911582) [configurations] - Add folder configuration from cwd: /home/user/dev/reactfrontend/.vim/coc-settings.json
  10. 2023-04-11T18:17:34.057 INFO (pid:911582) [plugin] - coc.nvim initialized with node: v16.15.1 after 224
  11. ...
  12. coc-tsserver veriosn 2.1.3 (latest)
  13. All plugins are updated.
  14. Yarn SDKs installed for typescript, prettier, eslint. Integrations: vim.

我已经试过升级yarn,升级sdks,升级neovim,重新安装依赖项。用一个简单的文件尝试yarn tsc,没有错误,并生成了一些js。

zaq34kh6

zaq34kh61#

最终发现我必须使用以下命令更改coc ts版本:

  1. :CocCommand tsserver.chooseVersion

并选择Local version而不是Bundled with coc-tsserver

相关问题