jenkins+sonar-scanner Scan Error: Failed to find ‘typescript’ module.Please check, NODE_PATH contains location of global ‘typescript’ or install locally in your project

Step: Jenkins sends out the task and uses the shell script to trigger the sonar scanner scan. report errors:

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

After trying for a day, it was finally solved. The method is as follows:

Premise: nodejs is installed.

1. Install typescript globally (I installed it. When I only installed the global separately, the task issued by Jenkins still reported an error. This step may be useless or useful. But I did, so it’s safer to record it).

Online installation method: NPM install – G typescript

————————————————————-

Offline installation method: first find a machine that can connect to the Internet and dig the package download address: the command is NPM info typescript Copy the tarball connection in the output and download it with the browser.

Copy to the sonar scanner machine, NPM install – G typescript-4.5.4.tgz

2. Locally install typescript (this step is very important and the key to success)

The path to execute the sonar scanner command (!! note here that it must be the path used to execute this command)

NPM install typescript (in offline mode, it is NPM install typescript-4.5.4.tgz. You will find that it will get stuck after running. If it’s OK, just exit. Three files node_modules. Package.json package-lock.json will appear in the directory)

Sudo Jenkins switches users and runs the sonar scanner command to see if there is still an error. If no error is reported, Copy the three JSON files (node_modules. package.json. package-lock.) into a new folder under rook.

The shell script in the Jenkins task reads as follows:

cd ${WORKSPACE}
sudo cp -r /root/workspace_bk/node_modules/ .
sudo cp -r /root/workspace_bk/package.json .
sudo cp -r /root/workspace_bk/package-lock.json .
sudo sonar-scanner ....

Similar Posts: