运行SonarQube扫描时出错:错误:第27行的文件[FILENAME]解析失败:“导入”和“导出”可能仅与“ sourceType:module”一起出现

问题描述

使用SonarQube运行Vue.js代码扫描时遇到一些问题。我正在使用SonarQube扫描仪(已安装纱线)运行扫描

yarn sonar-scanner

SonarQube Scanner

扫描似乎进行顺利,扫描确实完成,并且确实在SonarQube仪表板上获得了要修复的项目的列表-但是在扫描过程中的某个时刻,我收到了一些类似的错误消息:>

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

无论导入的是组件还是像Axios这样的模块,都会发生这种情况。

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

我看过的东西

  1. 确保在.eslintrc.json =>中将sourceType设置为'module'
  2. 检查SonarQube是否有Vue.js特定配置=>没有看到有关为Vue.js配置SonarQube的任何特定文档
  3. 看到了以下帖子,但没有使用TypeScript: SonarQube-Scanner fails to analyze Vue files - Failed to parse file [.vue]

任何建议都会受到赞赏。

解决方法

我只是摆脱了此错误,停止了在组件声明中动态导入

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

我将所有导入内容移至该语句的开头

import BasicTab from './Tabs/BasicTab'

可能不是解决方案,但至少这个错误消失了

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...