运行 SonarQube 扫描时出错: 错误: 无法解析第 27 行的文件 [文件名]: 'import' 并且'export'可能仅显示'sourceType: module'



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

yarn sonar-scanner

SonarQube扫描仪

扫描似乎进行得很顺利,扫描确实完成了,我确实在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扫描仪无法分析Vue文件-无法解析文件[.Vue]

如有任何建议,我们将不胜感激。

我刚刚摆脱了这个错误,停止在组件声明中动态导入

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

我将所有进口商品转移到声明的开头

import BasicTab from './Tabs/BasicTab'

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

相关内容

最新更新