如何设置TypeScript,VScode,Yarn2,Fastify项目

问题描述

我知道我以前已经解决了这个问题,但是从那以后情况可能发生了变化。我正在尝试主要使用Fastify,在TypeScript中使用VSCode进行编码以及使用Yarn2管理依赖项来建立一个新项目。

VSCode告诉我找不到固定值。即使同时添加了fastify和@ types / node,它也找不到节点类型。我尝试了以下许多排列和步骤,确保使用的是TypeScript的VSCode工作区版本,修改了tsconfig.json以使用节点moduleResultion,等等。无论过去的工作方式都不再起作用,但是我没有找不到其他解决该问题的最新文章或少量文档。

我想念什么?

nvm install node               ## Install latest NodeJS
node --version > .nvmrc        ## Set the node version to use
yarn init -y                   ## Project initialization
yarn set version Berry         ## Use yarn v2
yarn add --dev typescript      ## TypeScript all the way
yarn add --dev ts-node         ## Easier Ts script or task execution
yarn plugin import typescript  ## Magic?
yarn add --dev @types/node     ## Node types
yarn add --dev @yarnpkg/pnpify ## Emulate ./node_modules
yarn pnpify --sdk vscode       ## Setup workspace/environment     
yarn tsc --init -t ES2020      ## Generate tsconfig.json
yarn add fastify               ## Add fastify dep

enter image description here

enter image description here

package.json

{
  "name": "server","version": "1.0.0","main": "index.js","license": "MIT","devDependencies": {
    "@yarnpkg/pnpify": "^2.2.1","ts-node": "^9.0.0","typescript": "^4.0.3"
  },"dependencies": {
    "fastify": "^3.4.1"
  }
}

更新:尽管回答了VSCode使用TypeScript的工作区版本的提示,但我发现我仍然需要通过ctrl + shift + p手动指定它>选择TypeScript版本...之后,问题有所改变。不管导入语句如何,我现在都看到名称空间问题:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)