0

When executing sonarqube to generate a report, an error is reported in the report

ERROR: Failed to parse file [src/fetch/axios.ts] at line 1: ',' expected.

The first line in the ts file is

import axios, { type AxiosResponse } from 'axios'

If this line of code is placed in the Vue file, no sonarqube report error will be generated.
If I split this line of code into two sentences

import axios from 'axios';
import type { AxiosResponse } from 'axios'

there will be no sonarqube report error.
So, what is the reason for the error?
Is there any other solution besides splitting into 2 lines?

Jerryh001
  • 766
  • 2
  • 11
Tina
  • 11
  • 1
    You should end the line with `;` instead of `,`. Else yes, you can be able to do it with one line, but it's not obligatory – Elikill58 Apr 17 '23 at 07:26
  • Are you referring to this line of code,import axios, {type AxiosResponse} from 'axios'? Can you write the code? I didn't quite understand what you meant, sorry – Tina Apr 17 '23 at 07:32
  • Try `import axios, { AxiosResponse } from 'axios';` – Elikill58 Apr 17 '23 at 07:33
  • I have tried this writing method, and Sonarqube's report does not report any errors. But there are differences in whether to use type or not,here is the content I found. – Tina Apr 17 '23 at 07:41
  • So try `import axios from 'axios'; import type { AxiosResponse } from 'axios';` – Elikill58 Apr 17 '23 at 07:43
  • The import type syntax is used to import type declarations from a module. It means that the imported module will only be used for type checking and will not be included in the generated JavaScript code. This can help reduce the size of the compiled code and improve performance. On the other hand, import { AxiosResponse } from 'axios' is used to import the actual values exported from the module. This means that the imported module will be included in the generated JavaScript code and can be used at runtime. – Tina Apr 17 '23 at 07:45
  • Also, some post like [this one](https://stackoverflow.com/q/62217642/10952503) successed to do it. I think you have a typo such as wrong char before this line so it doesn't work properly – Elikill58 Apr 17 '23 at 07:46
  • Okay, thank you very much for your answer. This line of code is the first line in the file. The citation in this post is the same as you mentioned before, import axios, {AxiosResponse} from 'axios'. I am wondering if it is possible to solve the problem by modifying the tsconfig.json configuration file without changing the project code. – Tina Apr 17 '23 at 08:34
  • So please [edit] your post to make it more clear, add details and show config files. Also, for me it simply seems to be a typo – Elikill58 Apr 17 '23 at 09:45

0 Answers0