angular - שגיאת Jenkins: לא ניתן למצוא את המודול 'typescript'


יש לי פייפליין בג'נקינס שבו אני מנסה לסרוק אתר אנגולר עבור סונארקוב ונתקלתי בשגיאה הזאת:

ERROR: internal/modules/cjs/loader.js:582
ERROR:     throw err;
ERROR:     ^
ERROR: 
ERROR: Error: Cannot find module 'typescript'
ERROR:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
ERROR:     at Function.Module._load (internal/modules/cjs/loader.js:506:25)
ERROR:     at Module.require (internal/modules/cjs/loader.js:636:17)
ERROR:     at require (internal/modules/cjs/helpers.js:20:18)
ERROR:     at Object.<anonymous> (D:\SonarQube\ajbic-client-app\.scannerwork\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)
ERROR:     at Module._compile (internal/modules/cjs/loader.js:688:30)
ERROR:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
ERROR:     at Module.load (internal/modules/cjs/loader.js:598:32)
ERROR:     at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
ERROR:     at Function.Module._load (internal/modules/cjs/loader.js:529:3)
ERROR: Failed to find 'typescript' module. Please check, NODE_PATH contains location of global 'typescript' or install locally in your project
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE

ההגדרות שלי ב-Jenkins הן ככה:

steps {
        withSonarQubeEnv('Dev-build-01') {
            bat "cd D:/SonarQube/abcd-webapp"
            bat "rm -rf node_modules package-lock.json"
            bat "npm install"
            bat "C:/Jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQubeScanner/Net/bin/sonar-scanner.bat -D sonar.projectKey=abcd-webapp -D sonar.sources=src -D sonar.login=667723c08ecfe0fc0d5c0e91bdd5c4b219e851e7 -D sonar.projectBaseDir=D:/SonarQube/abcd-webapp"
        }
            timeout(time: 60, unit: 'MINUTES') {
              //   waitForQualityGate abortPipeline: true
                }
            }   
         }

עשיתי את הדברים הרגילים, התקנת את TypeScript (הורדה ובעזרת npm) אבל כל פעם אני מקבל את אותה השגיאה. גם דבר מוזר שקורה הוא שכאשר אני מסיר את השלב ושומר, צינור העבודה עדיין עובר דרך האנליזה.

יש למישהו רעיון מה לעשות?

תודה

תשובה #1

לאחר כמה שעות של התבוננות, הגעתי לפתרון, ולפני כן תן לי להסביר את הסיבה. הפרויקט הזה הורד מ-git (bitbucket), בפתרון אנחנו אף פעם לא מאפשרים ל-node_modules להיכלל בבדיקה. לכן במקרה הזה node_modules לא קיים. שנית, הבעיה (זו מחוץ לשליטתי), אין התקנה של פקודת bash, אלא שמישהו החליט להתקין תוסף powershell ואני צריך להתמודד עם זה. הפתרון היה להוסיף את powershell בסקריפט שלי והתוצאה הסופית היא

steps {
    withSonarQubeEnv('Dev-build-01') {
 powershell '''
        cd D:/SonarQube/abcd-webapp
        rmdir /q/s node_modules 
del package-lock.json
        npm install
'''
        bat "C:/Jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQubeScanner/Net/bin/sonar-scanner.bat -D sonar.projectKey=abcd-webapp -D sonar.sources=src -D sonar.login=667723c08ecfe0fc0d5c0e91bdd5c4b219e851e7 -D sonar.projectBaseDir=D:/SonarQube/abcd-webapp"
    }
        timeout(time: 60, unit: 'MINUTES') {
          //   waitForQualityGate abortPipeline: true
            }
        }   
     }

ולבסוף הצינור שלי תוקן.