VSCode和Typescript 5模块Resolution“bundler”
我正在尝试使用typescript 5。0.2和vscode 1。76.2,在tsconfig中设置了新的moduleResolution“bundler”。我正在用vite构建一个前端,所以typescript只用于–noEmit的类型检查。我可以让vscode和tsc --noEmit分别与不同的tsconfig一起工作,但不能让两者一起工作。
模块node 16
如果在tsconfig中。json我有
{
“module”: “node16”,
“moduleResolution”: “bundler”
…
}
然后Visual Studio Code工作得很完美,它对所有文件进行类型检查,一切都很棒。但是,运行tsc --noEmit会出现错误
tsconfig.json:4:25 - error TS5095: Option ‘bundler’ can only be used when ‘module’ is set to ‘es2015’ or later.
4 “moduleResolution”: “bundler”,
~~~~~~~~~
Found 1 error in tsconfig.json:4
模块es 2020
从上面的tsc错误,我尝试和改变tsconfig。json to have
{
“module”: “es2020”,
“moduleResolution”: “bundler”
…
}
现在运行tsc --noEmit工作得很好,它运行和类型检查一切都很完美。但是现在vscode坏了。当我在vscode中打开ts文件时,vscode无法解析任何引用。当我将鼠标移到像@mui/material这样的导入上时,vscode给出错误
Cannot find module ‘@mui/material’. Did you mean to set the ‘moduleResolution’ option to ‘node’, or to add aliases to the ‘paths’ option?
两个单独的tsconfig
现在,我只做了两个单独的tsconfig。tsconfig.json有“module”:“nodenext”,这样vscode就可以工作了,然后我将tsc指向一个单独的tsconfig。文件。
是否有一个可以同时使用tsc和vscode的tsconfig配置?
这实际上只是VSCode版本问题。
我使用的是VSCode 1。76.2我也有同样的问题。我在我的简历上有错误。config.js * 文件,当我导入 vite 和 @vitejs/plugin-react 时。此外,当我尝试导入第三方库时,在任何其他文件中都有错误。在那个VSCode版本中,我发现的唯一修复是在tsconfig中将bundler更改为node。json和tsconfig。node.json**
bundler模块分辨率是一个新特性,在Typescript 5上实现。0,我认为VSCode还没有100%准备好。
我刚刚更新了这里(现在我有VSCode 1。77.3),并且可以更改回两个tsconfig。json和tsconfig。node.json模块解析为bundler。没有问题了!