Error: Cannot find module 'typescript'

Template for a good bug report, formatted with Markdown:

  • versions used (SonarQube, Scanner, Plugin, and any relevant extension)
  • Community Edition Version 7.4 (build 18908)

I am using Team City as my CI.
SQ is being hosted in a Win Server 2012 R2. 12 gb of Ram. I have more than 50gig free.
When I have task manager RAM only 40% used

I have added several projects to SonarQube. Only a couple of project i encounter “Can not find typescript”
According to documentation I my version is higher than the min. requirements.

if you take a look at another issue I posted, it list all the plug-in installed and version. Out of memory: Java heap space

Hi @RyanK,

SonarTS, i.e. our plugin used to analyze TypeScript files, needs to have “TypeScript” node module available either globally or locally on your project.

Given you already have node.js installed on your machine, you have two options:

  • (Recommended) Running npm install before starting an analysis on each of your TS project to make TypeScript module available.
  • Install TypeScript globally by running npm install -g typescript

Hope it clarifies.

Andrea

Thanks @Andrea_Guarino

I tried installing it globally, but it did not work. I had to have the type script install on per build configuration. Good thing I am using templates.

1 Like

Hi RyanK,
I am facing same error in my jenkins build while sonarscanner analyzing .ts file. I don’t know what exactly need to be done. I am familiar in sonar; but not in node.js. My very first question is: Is sonar using node.js to analyze .ts files? I tried installing it globally as > npm install -g typescript; but didn’t work.

I tried setting up our NODE_PATH by using “-Dsonar.typescript.node=” variable; but still facing the above error.

It would be great help if can guide me that how did you install type script on per build configuration? Thanks in Advance.

Hi Faizur

Its been a while. I do not full recall what we did to resolve the issue.
With was either upgrade or downgrade the plug-in and/or fix the windows environment path.

Remember this is a Java base tool. Most errors that kick out does not provide a good idea what the issue is and/or there is a version issue from Operating system, Java runtimes, plug-ins, etc…

Thanks Ryan K for your response. plugin means sonar related plugin for typescript i.e., under $SONAR_HOME/extensions/plugins?

1 Like

I believe so…
It could be the CI server, instead of the SQ server you need to make sure things are configured.

I am facing same error in my Azure Devops build .
I tried the commands:

setx NODE_PATH “$(Build.SourcesDirectory)\node_modules” /M

cd $(Build.SourcesDirectory)

npm install -D typescript

But the error continues.

Any thoughts?

Sorry Aecio

I would suggest to make sure you have an update node and npm version.

npm -v
node -v

I have been having a difficulties trying to get the MS Build to run. Not getting that much support over here. I am going to look at another tool before I make any purchase.

Thanks, Ryan K.

After several attempts, I got SonarQube to work properly on Azure Devops.
Sonar worked only by installing the typescript module for each project. No need NODE_PATH variable.
For each project in the solution that has typescript code, run the following code in command line:
cd $(Build.SourcesDirectory)<PROJECT_FOLDER>
npm install typescript.

I hope this helps.

1 Like

Ah… Thanks @aeciobf

That does ring a bell. I double checked my Team City template and my PowerShell function. I do have a step to install typescript during the CI process. The PS script I am using is

npm install prerender-node --save;

Note: my PS script is a long switch statement with custom execution for CI build process… (ie… install type script, npm install commands, etc…). I did this so I only need to change 1 file and push that fill to all Team City Agents when things change instead of going to make changes to multiple process templates

Sorry @faizurrahmann - I forgot about this.

Thanks a lot, it worked for me.