Jenkins错误:找不到模块'typescript'。

3

我有一个Jenkins Pipeline,在尝试使用SonarQube扫描Angular网站时遇到了这个错误:

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个回答

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
            }
        }   
     }

最后,我的管道被修好了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接