问题描述
使用SonarQube运行Vue.js代码扫描时遇到一些问题。我正在使用SonarQube扫描仪(已安装纱线)运行扫描
yarn sonar-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';
我看过的东西
- 确保在.eslintrc.json =>中将sourceType设置为'module'
- 检查SonarQube是否有Vue.js特定配置=>没有看到有关为Vue.js配置SonarQube的任何特定文档
- 看到了以下帖子,但没有使用TypeScript: SonarQube-Scanner fails to analyze Vue files - Failed to parse file [.vue]
任何建议都会受到赞赏。
解决方法
我只是摆脱了此错误,停止了在组件声明中动态导入
components: {
BasicTab: () => import('./Tabs/BasicTab'),
我将所有导入内容移至该语句的开头
import BasicTab from './Tabs/BasicTab'
可能不是解决方案,但至少这个错误消失了