zl程序教程

您现在的位置是:首页 >  前端

当前栏目

vue eslint报错:TypeError: token.type.endsWith is not a function

Vue 报错 not is type Function Token TypeError
2023-09-27 14:24:12 时间

原文地址:https://jue.leheavengame.com/article/61b4946d3a91de0b5dc12930

问题发现

维护了很久的vue项目,发现eslint会报错:TypeError: token.type.endsWith is not a function
image

问题原因

babel-eslintnpm包已被弃用,我们无法再下载到这个包,导致项目缺少依赖报错。
image

问题解决

将弃用的babel-eslint换成@babel/eslint-parser即可。

  • 先移除依赖:yarn remove babel-eslint或者npm uninstall --save-dev babel-eslint
  • 然后添加依赖:yarn add --dev @babel/eslint-parser或者npm install --save-dev @babel/eslint-parser
    注意:eslinteslint-plugin-vue依赖也是必须的,项目若没有也需要添加。
  • 最后修改.eslintrc.js文件配置:
parserOptions: {
   parser: '@babel/eslint-parser'
}