我在 Visual Studio 2022 下为我的 SPA 创建了一个项目 (.esproj)。 它构建良好,但 Visual Studio 显示了很多错误(仅针对项目的 node_modules 中的 .dt.ts 文件以及 AppData 中本地安装的 Typescript 之一)。
错误不会显示在 VS Code 上,但理想情况下我会使用 Visual Studio 2022。
这是我的esproj
<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/0.5.0-alpha">
<PropertyGroup Label="Globals">
<ProjectGuid>6b86a87b-eb34-43fe-9cbb-99a2e3db4e41</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<StartupCommand>set BROWSER=none&&npm start</StartupCommand>
<JavaScriptTestRoot>src\</JavaScriptTestRoot>
<JavaScriptTestFramework>Jest</JavaScriptTestFramework>
</PropertyGroup>
<ItemGroup>
<Script Include="**" Exclude="*.esproj;**\node_modules\**" />
</ItemGroup>
<!-- This target is copied from the ASP.NET SPA template in order to ensure node_modules are in place. -->
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install --legacy-peer-deps" />
</Target>
</Project>
这里是我的 tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"target": "ESNext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
}
知道如何配置 Visual Studio 2022 使其不在 .d.ts 上运行分析器吗?
提前致谢
这对我有用,更改 .csproj 以将此设置包含在 PropertyGroup 中:
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
更换有效负载部分
<ItemGroup>
<Script Include="**" Exclude="*.esproj;**\node_modules\**" />
</ItemGroup>
由
<ItemGroup>
<Script Include="**"/>
<Script Remove="**.d.ts"/>
</ItemGroup>
似乎解决了我的问题
更快的解决方案加载,不再出现智能感知错误,即使文件夹被隐藏,NPM 仍然可以工作。
我的同事建议进行此修复,它似乎已从 Visual Studio 错误列表中删除了所有打字稿错误。
转到您的项目所在的文件夹并查找名为“node_modules”的文件夹。
右键单击该文件夹并选择“属性”。
单击“隐藏”复选框。
单击“确定”,将出现一个弹出菜单,询问您是否要“将更改应用到此文件夹、子文件夹和文件”。选择“确定”。
所有 778 个打字稿错误在 Visual Studio 2022 上都消失了。
进入当前用户目录
启动/运行 %USERPROFILE% 或 C:\Users\
\
找到名为 node_modules
的文件夹删除它
重建项目