cathive / concourse-sonarqube-resource

performs SonarQube analyses and checks quality gates https://concourse-ci.org/ https://sonarqube.org/
Apache License 2.0
46 stars 50 forks source link

Error: Cannot find module 'typescript' #51

Closed Lubytes closed 4 years ago

Lubytes commented 4 years ago

Even with the RUN npm install -g typescript@${TYPESCRIPT_VERSION} in the latest version I'm still getting the following error:

Sensor SonarTS [typescript]
    throw err;
    ^

Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js.581.15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
...
Failed to find 'typescript' module. Please check, NODE_PATH contains location of global 'typescript' or install locally in your project
External process `node --max-old-space-size=2048 /tmp/build/put/app .scannerwork/sonarts-bundle/node_modules/tslint-sonarts/bin/tsrunner` returned as empty output

Doing which typescript inside the docker image also shows it can't find typescript. There's only tsc and tsserver.

headcr4sh commented 4 years ago

The NPM package typescript does'nt contain any binary that goes by the name typescript. Therefore, I assume this is not an error.

However, I am not sure why the module/package typescript seems to be missing. Maybe the NODE_PATH variable cannot be resolved correctly. But that's only a guess right now.

Can you run the resource with __debug: true in it's source configuration? Maybe the full and verbose log output can provide better insights into what's going on.

Lubytes commented 4 years ago

Unfortunately __debug: true did not yield any useful output corresponding to this issue.

Lubytes commented 4 years ago

I launched a container with my project in it and tried a couple different things. Here's what I found:

linking typescript

By doing npm link typescript inside my project in the container, it created a node_modules folder with a linked version of the global typescript module inside my project. This fixed my Error: Cannot find module 'typescript' issue. But I still have a java.lang.IllegalStateException: Error parsing the report '/root/my-project/.scannerwork/sonarts-bundle/node_module/node_modules/path-parse/test.js' at the end (I had this before). I'm not sure if this is related or if adding an exception to node_module/* will fix it.

Anyway, this shows that the sonar-scanner is having a hard time picking up the global typescript module when evaluating. Unfortunately linking isn't an option when we're running this right out of a container, so we still need a global fix.

NODE_PATH

I added ENV NODE_PATH /usr/local/lib/node_modules to the docker image and that seemed to do the trick for the typescript module issue. I'm still faced with the IllegalStateException but I'm going to try some stuff on my own and open a new ticket if necessary.