# Error Sonar \[error\]Unhandled: Unexpected token AzureDevops

**URL:** <https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076>\
**Category:** SonarQube Server / Community Build\
**Tags:** azuredevops, pipeline, sonar-scanner, sonarqube\
**Created:** [November 27, 2023, 4:40pm UTC](https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076 "2023-11-27T16:40:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Alejandro\_Anto](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/david_alejandro_anto/32/50543_2.png) [@David\_Alejandro\_Anto](https://community.sonarsource.com/u/David_Alejandro_Anto)\
**Post date:** [November 27, 2023, 4:40pm UTC](https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076/1 "2023-11-27T16:40:11Z")

</div>

Hello, I am having an error when running a pipeline in azure devops, the pipeline generates an error in the sonarqube prepare phase, I am using sonar version 5.18.3 (Latest), in the self-hosted agent I have node16.13.2 and I tried with version 18 getting the same error the, error is the following.

```auto
##[error]Unhandled: Unexpected token ...
##[error]C:\Users\davidantolinez\Documents\my_agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.36.0\node_modules\hpagent\index.js:9
    const { proxy, proxyRequestOptions, ...opts } = options.

```

the pipeline is this

```auto
jobs:
- job: 'analysis'
  displayName: 'analysis with sonar'

  steps: 
  
  - checkout: none

  - task: SonarQubePrepare@4
    inputs:
        SonarQube: 'mySonarqube'
        scannerMode: 'CLI'
        configMode: 'manual'
        cliProjectKey: 'nodejs'
        cliProjectName: 'nodejs'
        cliAdditionalArgs: >
          sonar.sources=$(Build.SourcesDirectory)/src
          # sonar.tests=$(Build.SourcesDirectory)/src/ __test__ 
          # sonar.exclusions=$(Build.SourcesDirectory)/src/ __test__ /**
          # sonar.testExecutionReportPaths=$(Build.SourcesDirectory)/test-report.xml 
          # sonar.javascript.lcov.reportPaths=$(Build.SourcesDirectory)/coverage/lcov.info"

  - task: SonarQubeAnalyze@4
    displayName: 'Run SonarQube analysis'

  - task: SonarQubePublish@4
    inputs:
      pollingTimeoutSec: '300'

```

Im using a docker image of sonar the lts version i also ran a jenkins pipeline to verify the connection with sonar and it worked, someone can help me with this error.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [November 29, 2023, 3:14pm UTC](https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076/2 "2023-11-29T15:14:03Z")

</div>

Hey there.

It’s not clear to me what’s happening in your pipeline when you get these logs.

> [@David\_Alejandro\_Anto](#):
>
> ```auto
> ##[error]Unhandled: Unexpected token ...
> ##[error]C:\Users\davidantolinez\Documents\my_agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.36.0\node_modules\hpagent\index.js:9
> const { proxy, proxyRequestOptions, ...opts } = options.
> 
> ```

Can you offer a wider range of logs?

---

<div class="post-metadata">

**Author:** ![sk92129](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sk92129/32/52319_2.png) [@sk92129](https://community.sonarsource.com/u/sk92129)\
**Post date:** [December 4, 2023, 11:05pm UTC](https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076/3 "2023-12-04T23:05:21Z")

</div>

Is there a solution for this?  
I have a similar problem where the agent is running on centos 7 with kernerl 3.

I can see that it looks like something does not like the “merge” javascript operator,

I wrote a quick JavaScript test function and ran on the centos.

> <https://github.com/sk92129/JavaScriptExamples/blob/main/index.js>

The merge operation works fine on the centos.

And the version of node is 16.20.2  
npm is 8.19.4

```auto
##[debug]loading ENDPOINT_AUTH_SCHEME_c876f7df-5dc1-4d93-bdb5-596fc3e75b75
##[debug]loading ENDPOINT_AUTH_PARAMETER_c876f7df-5dc1-4d93-bdb5-596fc3e75b75_USERNAME
##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
##[debug]loaded 15
##[debug]Agent.ProxyUrl=undefined
##[debug]Agent.CAInfo=undefined
##[debug]Agent.ClientCert=undefined
##[debug]Agent.SkipCertValidation=undefined
##[debug]task result: Failed
##[error]Unhandled: Unexpected token ...
##[debug]Processed: ##vso[task.issue type=error;]Unhandled: Unexpected token ...
##[debug]Processed: ##vso[task.complete result=Failed;]Unhandled: Unexpected token ...
##[error]/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/node_modules/hpagent/index.js:9
    const { proxy, proxyRequestOptions, ...opts } = options
                                        ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/common/sonarqube/Endpoint.js:24:17)
##[debug]Processed: ##vso[task.issue type=error;]/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/node_modules/hpagent/index.js:9
    const { proxy, proxyRequestOptions, ...opts } = options
                                        ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/common/sonarqube/Endpoint.js:24:17)
Finishing: SonarQubePrepare

```

Latest update Dec 4 - 4:32PM PST  
I changed the version of the SonarQubePrepare@4 to SonarQubePrepare@5 and that seems to get past the JavaScript error.

Now facing the issue of trying to access the onsite agent from outside.

```auto
Starting: SonarQubePrepare
==============================================================================
Task : Prepare Analysis Configuration
Description : Prepare SonarQube analysis configuration
Version : 5.18.4
Author : sonarsource
Help : Version: 5.18.4. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
##[error][SQ] API GET '/api/server/version' failed, error is request to http://localhost:9000/api/server/version failed, reason: connect ECONNREFUSED 127.0.0.1:9000
Finishing: SonarQubePrepare

```

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 5, 2023, 9:33am UTC](https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076/4 "2023-12-05T09:33:07Z")

</div>

It looks like in both cases, `hpagent` is causing trouble with _v4_ of the task.

We reccomend using _v5_, but since I think this is unexpected (this is a [new dependency](https://github.com/SonarSource/sonar-scanner-vsts/commit/2495880e71a43a41b77390015e554e52178bd8c6)) I’ll flag this for attention.

---

<div class="post-metadata">

**Author:** ![benjamin.raymond](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/benjamin.raymond/32/41399_2.png) [@benjamin.raymond](https://community.sonarsource.com/u/benjamin.raymond)\
**Post date:** [December 6, 2023, 5:07pm UTC](https://community.sonarsource.com/t/error-sonar-error-unhandled-unexpected-token-azuredevops/105076/7 "2023-12-06T17:07:05Z")

</div>

Hello 👋

@David_Alejandro_Anto @sk92129

There are two issues at play here

# 1

> ##[error]Unhandled: Unexpected token …

This one is related to V4 of the tasks. Even if your agent has node 16/18 binaries, V4 of the task will always be run using node 6 which can’t parse the object destructuring, thus explaining this error. This can be fixed by moving to V5 of the tasks.

# 2

> ##[error][SQ] API GET ‘/api/server/version’ failed, error is request to [http://localhost:9000/api/server/version](http://localhost:9000/api/server/version) failed, reason: connect ECONNREFUSED 127.0.0.1:9000

@sk92129 The error means that the agent running the task is trying to reach your SQ at `localhost:9000`. This URL should be the URL of your SQ, from the perspective of where the task is running (either self-hosted agent, or Microsoft agent). You can fix this URL by updating your SonarQube Service Connection.

FYI: If the agent has to go through a proxy to reach the SQ, you will also have to set up HTTP\_PROXY/HTTPS\_PROXY environment variables.

Hope this helps!
