VMx

vmx.im
啥都学一点的填坑人
  1. 首页
  2. vue
  3. 正文

vite typescript 报错 es-lint Parsing error: Unexpected token )eslint

2022年12月22日 832点热度 0人点赞 0条评论

非 eslint参考 https://segmentfault.com/a/1190000041954694
网上很多配置都是使用 @babel/eslint-parser,而使用 vite 的时候是没有 babel的配置的,这样就无法使用.
eslint-parser 这个不能按原文章安装。
参照:
https://stackoverflow.com/questions/70083042/eslint-parsing-error-unexpected-token
vue ts 报错 vite es-lint Parsing error: Unexpected token )eslint

安装 parse ts

yarn add -D @typescript-eslint/parser
yarn add -D @typescript-eslint/eslint-plugin

修改 .eslintrc文件

parserOptions: {
...
parser: '@typescript-eslint/parser'
}

eslint 8.56版本以上

因eslint 8.56后,弃用了 .eslintrc 文件,改成了 eslint.config.js

import tsParser from '@typescript-eslint/parser';
export default[
    languageOptions: {
        parser: tsParser,
        parserOptions: {
            ecmaFeatures:{modules: true},
            ecmaVersion: 'latest',
            parser: '@typescript-eslint/parser'
            },
    }
    {
     rules: {
     //...
     }
    }
]

附上自用简单 eslint.config.js

import globals from 'globals'
import pluginJs from '@eslint/js'
import tseslint from 'typescript-eslint'
import pluginVue from 'eslint-plugin-vue'
import tsParser from '@typescript-eslint/parser'

export default [
  {
    languageOptions: {
      globals: globals.browser,
      parser: tsParser,
      parserOptions: {
        ecmaFeatures: { modules: true },
        ecmaVersion: 'latest',
        parser: '@typescript-eslint/parser'
      }
    }
  },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  ...pluginVue.configs['flat/essential'],
  {
    rules: {
      'vue/multi-word-component-names': ['off'],
      '@typescript-eslint/no-explicit-any': ['off'],
      'no-unsafe-optional-chaining': ['warn'],
      'vue/valid-v-for': ['off']
    }
  }
]
Post Views: 707
标签: 暂无
最后更新:2024年5月10日

huifei

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2021 vmx.im. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang