24

I created a project (.esproj) for my SPA under visual studio 2022. It build well but visual studio is showing a lot of errors (only on .dt.ts files from node_modules of the project and also from the one of Typescript locally installed in AppData).

The errors are not showing up on VS Code but ideally I would use visual studio 2022 for this.

Here my 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&amp;&amp;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>

here my 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"
  ]
}

Any idea how I can configure visual studio 2022 to not run analyzer on .d.ts ?

Thanks in advance

Erwan Joly
  • 491
  • 1
  • 4
  • 14
  • 5
    Same, 322 errors when I build, all from node_modules. What makes it slightly worse is I'm definitely not compiling any typescript in VS, webpack handling all that. – James White Dec 15 '21 at 23:44
  • I want to share [this](https://stackoverflow.com/a/71774397/18730060) which is my solution for this issue. – Josh Apr 07 '22 at 01:24

4 Answers4

23

This worked for me change .csproj to include this setting inside PropertyGroup:

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
user3670176
  • 231
  • 2
  • 4
12

Replacing the payload part

 <ItemGroup>
        <Script Include="**" Exclude="*.esproj;**\node_modules\**" />
    </ItemGroup>

by

  <ItemGroup>
    <Script Include="**"/>
    <Script Remove="**.d.ts"/>
  </ItemGroup>

seems to solve my issue

Erwan Joly
  • 491
  • 1
  • 4
  • 14
  • 4
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 23 '21 at 23:11
  • I tried this approach and the typescript errors still appear. – minTwin Aug 11 '22 at 14:21
  • this worked for me! However, I noticed that it was duplicating some of my files (i.e. package.json) - so I removed the and then everything displayed correctly and there were no TS errors. If I had to guess I had the include somewhere else in my CSProj file. – webdad3 Nov 21 '22 at 17:54
9
  1. In Visual Studio, Right click the node_modules folder and select 'Exclude From Project' if not already set.
  2. Close your solution in VS.
  3. Using File Explorer, set the properties of the node_modules folder to Hidden (do not apply to sub folders).
  4. Open your solution.

Faster solution load, no more intellisense errors, NPM still works even though the folder is hidden.

John Rah
  • 1,757
  • 1
  • 14
  • 13
1

My colleague suggested this fix and its seems to have removed all the typescript errors from the visual studio error list.

  1. Go to the folder where your project is located and look for a folder called "node_modules".

  2. Right click that folder and select "properties."

  3. Click the "Hidden" checkbox.

  4. Click "OK" and a popup menu will appear that asks you if you want to "Apply changes to this folder, subfolders, and files". Select "OK".

All 778 typescript errors disappeared on Visual Studio 2022.

minTwin
  • 1,181
  • 2
  • 21
  • 35