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?
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.
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.
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.
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?
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?