【问题标题】:Jenkins-Error: Cannot find module 'typescript'詹金斯错误:找不到模块'打字稿'
【发布时间】:2019-12-21 01:49:33
【问题描述】:

我有一个 jenkins 管道,我正在尝试扫描一个角度网站以查找 sonarqube,但我遇到了这个错误:

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),但每次我都遇到同样的错误。 还有一件奇怪的事情是,当我删除阶段并保存时,管道仍在进行分析。

有人知道该怎么做吗?

谢谢

【问题讨论】:

    标签: angular typescript sonarqube sonarqube-scan


    【解决方案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
                }
            }   
         }
    

    最后我的管道被修复了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-30
      • 2014-07-24
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多