3

I noticed that whenever I switch a branch in Git, Resharper will start throwing hundreds of errors in TypeScript. The only way to resolve this is to delete node_modules folder and run npm install again. This is a bit of a burden doing it every time as I am switching between branches and creating new ones whenever there is a task to be worked on.

Has anyone had a similar issue and how did you resolve it without reinstalling node modules? I am using ReSharper Ultimate 2016.3.2 (January 26, 2017 build).

UPDATE:

Let me update this question a bit. ReSharper will mark the errors where they do not exist. Even in this state the TypeScript code can be compiled without any problems. Pressing CTRL+SHIFT+ALT+8 disables ReSharper analysis for that TypeScript file and we are back to normal Visual Studio (as if ReSharper was not installed). The issue is not with NPM modules or Git settings. The problem is somewhere with how ReSharper tries to pickup the branch switching. Something confuses it.

Community
  • 1
  • 1
Huske
  • 9,186
  • 2
  • 36
  • 53
  • You can try to add "ignore" rule for `node_modules` in code inspection settings - this should improve overall performance of IDE as well – Aleksey L. Feb 28 '17 at 14:39
  • @AlekseyL. this did not work. – Huske Feb 28 '17 at 14:46
  • Could you please confirm where these error messages are being generated from? It _sounds_ like the NPM modules are generating the errors but confirmation would be helpful. – Rich Seviora Mar 03 '17 at 03:18

1 Answers1

1

As @Aleksey L. mentions, you need to add ignore rule to your .gitignore for the node_modules. But for this to work, you need to remove the modules from the repository by doing:

git rm --cached <file> for every module

you can even try git update-index --assume-unchanged <file> if you don't want to create an ignore rule,as suggested in this answer: How to stop tracking and ignore changes to a file in Git?

Another possible workaround maybe to fidle a bit with Reshaper's settings:

Goto Options > Code Inspection > Settings > Elements to skip > Add node_modules

Options > Code Editing > Third-Party Code > Library code > Add node_modules

As suggested in this thread: Visual Studio Resharper with TypeScript and node_modules

After Question Update:

There is a suggestion on the last comment of this article: https://resharper-support.jetbrains.com/hc/en-us/community/posts/206014479-False-Positives-after-Git-Checkout-

Goto Options > General > Clear Caches and then restart

Community
  • 1
  • 1
John Moutafis
  • 22,254
  • 11
  • 68
  • 112
  • This has nothing to do with git. `node_module` are not tracked and are not cached. The problem is with ReSharper's analysis. As for `Elements to Skip` in ReSharper, only folders that are part of the solution can be added. – Huske Mar 03 '17 at 06:21
  • I have edited my answer, see if that helps you in any way :) – John Moutafis Mar 04 '17 at 15:38
  • Great stuff. Clear Cache did the trick. I need to point out that after Visual Studio restart, the project took slightly longer to load prior to Resharper kicking in to perform the solution-wide analysis. Thanks John for this answer. – Huske Mar 04 '17 at 18:59
  • 1
    Nice to know that helped mate :D. The whole deal sounds like a bug of resharper and you probably can raise an issue... – John Moutafis Mar 04 '17 at 20:48