newtmitch / docker-sonar-scanner

Quick sonar scanner docker image
MIT License
129 stars 88 forks source link

Error checking Typescript files in alpine image #36

Closed squaricdot closed 3 years ago

squaricdot commented 4 years ago

Dear,

It might be entirely me.

But I have a project which I try to analyse.

I tried to use your public image based on Dockerfile.sonarscanner-4.0.0-alpine

so far I got errors as when running the scan as:

docker run --rm -i -v $JENKINS_JOB_WORKSPACE:/usr/src --entrypoint= myregistry/docker-sonar-scanner:4.0.0 /usr/local/bin/sonar-scanner -Dsonar.host.url=https://sonar.mydomain.org -Dsonar.sources=src -Dsonar.projectKey=myproject -Dsonar.projectName=myproject

18:05:02 ERROR: Error: Cannot find module 'typescript' 18:05:02 ERROR: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15) 18:05:02 ERROR: at Function.Module._load (internal/modules/cjs/loader.js:507:25) 18:05:02 ERROR: at Module.require (internal/modules/cjs/loader.js:637:17) 18:05:02 ERROR: at require (internal/modules/cjs/helpers.js:22:18) 18:05:02 ERROR: at Object. (/usr/src/.scannerwork/sonarts-bundle/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.js:20:10) 18:05:02 ERROR: at Module._compile (internal/modules/cjs/loader.js:689:30) 18:05:02 ERROR: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) 18:05:02 ERROR: at Module.load (internal/modules/cjs/loader.js:599:32) 18:05:02 ERROR: at tryModuleLoad (internal/modules/cjs/loader.js:538:12) 18:05:02 ERROR: at Function.Module._load (internal/modules/cjs/loader.js:530:3) 18:05:02 ERROR: Failed to find 'typescript' module. Please check, NODE_PATH contains location of global 'typescript' or install locally in your project 18:05:02 ERROR: External process node --max-old-space-size=2048 /usr/src/.scannerwork/sonarts-bundle/node_modules/tslint-sonarts/bin/tsrunner returned an empty output. Run with -X for more information

We checked out the image and could see that typescript should be present on the box.

I tried manually changing or providing NODE_PATH by updating yours Dockerfile.sonarscanner-4.0.0-alpine

So far that did not work.

After hours of testing I finally managed to get rid of the error by adding

RUN npm install -g typescript
ENV NODE_PATH=/usr/lib/node_modules

to Dockerfile.sonarscanner-4.0.0-alpine and build by own.

So far this got rid of the problem but I feel like a retard.

Is there something I absolutely am doing wrong. Can't believe I fixed it just found a work around.

Looking forward to your response!

Best regards, OImo

squaricdot commented 4 years ago

We were able to find another work around by providing npm install to the docker run command

docker run -it --rm -v $(pwd):/usr/src --link sonarqube --entrypoint /bin/sh newtmitch/sonar-scanner:alpine -c "cd /usr/src && npm i && sonar-scanner --debug -Dsonar.host.url=http://sonarqube:9000 -Dsonar.projectKey=myproject -Dsonar.projectName=myproject -Dsonar.projectBaseDir=/usr/src -Dsonar.working.directory=/tmp/.scannerwork"

but this still feels like an hack. though it works without having to change the Dockerfile

newtmitch commented 3 years ago

@squaricdot I just tried this locally with a javascript/typescript project of my own and it processed correctly and identified it as typescript in the project summary entry. I used the simple commands from the readme for local projects:

docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
docker run -ti -v $PWD:/usr/src --link sonarqube newtmitch/sonar-scanner-alpine

It's possible you have something environmental going on, but if you want to try again, you might try with the latest 4.5 version of Sonar Scanner (I just pushed new images last night) and also see if you can test locally and manually to rule out your Jenkins server itself as core to the issue.

I'm going to close this issue for now and reopen if you find something definitive that should be addressed.