Error when running SonarQube scan: ERROR: Failed to parse file [FILENAME] at line 27: 'import' and 'export' may appear only with 'sourceType: module'

Viewed 1746

I'm having some issues running a scan of Vue.js code with SonarQube. I'm running the scan using SonarQube scanner (installed with yarn)

yarn sonar-scanner

SonarQube Scanner

The scan appears to go well, the scan does complete and I do get a list of items to fix on the SonarQube dashboard - however at some point I receive a wall of errors like these in the middle of the scan:

ERROR: Failed to parse file [FILENAME] at line 27: 'import' and 'export' may appear only with 'sourceType: module'

This happens regardless of whether it's importing a component or just a module like Axios.

import Axios from 'axios'
import Component from '@/src/js/global/component';

Things i've looked at

  1. Make sure sourceType is set to 'module' in .eslintrc.json => It is set to module
  2. Checking if there is a Vue.js specific configuration for SonarQube => Do not see any specific documentation regarding configuring SonarQube for Vue.js
  3. Saw the following post, but not using TypeScript: SonarQube-Scanner fails to analyze Vue files - Failed to parse file [.vue]

Anyone suggestions would be appreciated.

1 Answers

I just get rid of this error stopping importing dynamically inside components declarations

  components: {
    BasicTab: () => import('./Tabs/BasicTab'),

I moved all the imports to the beggining of the statement

import BasicTab from './Tabs/BasicTab'

It may not be the solutions but at least this error is gone

Related