TypeScript error with Azure DevOps


(Timothy Snyder) #1

I have a build process in Azure DevOps for a web application that includes TypeScript files. I am stuck on this error:

ERROR: Failed to find ‘typescript’ module. Please check, NODE_PATH contains location of global ‘typescript’ or install locally in your project

What I have tried:

  • installed TypeScript SDK on my build agent.
  • ran npm install -g TypeScript on the build agent.
  • ran on the agent: SET NODE_PATH=%AppData%\npm\node_modules
  • added Microsoft.TypeScript.Compiler nuget package to the project.
  • added “npm install” step to the build process just before the Run Code Analysis step. (I didn’t set the working directory for the package.json since I wasn’t sure where the relevant directory would be that contains the packages that sonarsource needs.)

Could someone please explain what either of the suggested options from the error message mean?
“NODE_PATH contains location of global ‘typescript’” - Is this the TypeScript compiler program? What executable is this looking for? Assuming NODE_PATH is an environment variable.
“install locally in your project” - install what to where? Does “project” mean “source code”? Add a reference via NuGet?


(G Ann Campbell) #2


By default, analysis is looking for Node.js in %PATH%. If it’s not there, you can use sonar.typescript.node to specify where it is. Details in the docs.


(Timothy Snyder) #3

I added the location of node.js to the PATH environment variable. I also ran the install step from the docs you mentioned: npm install -D typescript. Neither resolve the issue.

Where do I use sonar.typescript.node?

(G Ann Campbell) #4


In your case, I think you would pass the property on the command line with /d:param=key. (Docs)


(Elena Vilchik) #5

Looks like everything is ok with Nodejs itself, problem is in typescript. SonarQube needs typescript dependency being available in node_modules directory at the moment of analysis.

So what I can suggest is to add npm install typescript step to the build process before the analysis.

If it still fails please show debug logs.

(Timothy Snyder) #6

Still not working. Do you mean the build logs from Azure DevOps?

(Timothy Snyder) #7

I’m using the Run Code Analysis plugin in Azure DevOps so I don’t have a command line. There are no configuration options for that plug in. Is there another way to inform sonar where to find the typescript module?

(Timothy Snyder) #8

I’m still not getting anywhere with getting this resolved. Does anyone have a guide to using SonarCloud with Azure DevOps on a .NET web application that includes TypeScript files?

Or is there a way to ignore TypeScript files to at least get the initial scan going?

(Luuk Sommers) #9

I solved it by creating a variable in the build pipeline called NODE_PATH with the value $(Build.SourcesDirectory)/node_modules/

Maybe this helps?

(Timothy Snyder) #10

That did it. Thank you so much!