[英]ESLint: Parsing error: Unexpected token :
Hi everyone I am migrating my vue3 project from js to typescript, I run into this problem:大家好我正在将我的vue3项目从js迁移到typescript,我遇到了这个问题:
Here is my code in.vue file这是我的代码 in.vue 文件
<script setup lang="ts">
const toto = (msg: string) => {
console.log(msg)
}
</script>
And here is my eslintrc.js这是我的 eslintrc.js
module.exports = {
'env': {
'browser': true,
'es2021': true
},
'extends': [
'eslint:recommended',
'plugin:vue/vue3-essential'
],
'parserOptions': {
'ecmaVersion': 13,
'sourceType': 'module'
},
'plugins': [
'vue'
],
'rules': {
'vue/multi-word-component-names': 'off',
'vue/object-curly-spacing': [2, 'always'],
'vue/html-closing-bracket-spacing': [2, {
'selfClosingTag': 'always'
}],
'vue/max-attributes-per-line': [2, {
'singleline': {
'max': 1
},
'multiline': {
'max': 1
}
}],
'semi': [2, 'never']
}
}
Could someone please help me?有人可以帮我吗? thank you
谢谢你
In my case, the problem was that I was using the parser option as an array, instead of a string:在我的例子中,问题是我将解析器选项用作数组,而不是字符串:
parserOptions: {
- parser: ['@typescript-eslint/parser'],
+ parser: '@typescript-eslint/parser',
},
You need to configure eslint to support typescript as eslint doesn't support it out of the box.您需要配置 eslint 以支持 typescript 因为 eslint 开箱即用不支持它。 First, you need to install @typescript-eslint/parser and then @typescript-eslint/eslint-plugin .
首先,您需要安装@typescript-eslint/parser然后@typescript-eslint/eslint-plugin 。 Once you have installed these, simply update your config as follows-
一旦你安装了这些,只需更新你的配置如下 -
module.exports = {
'env': {
'browser': true,
'es2021': true,
node: true
},
'extends': [
'eslint:recommended',
'plugin:vue/vue3-essential'
],
'parserOptions': {
'ecmaVersion': 12,
'sourceType': 'module',
parser: '@typescript-eslint/parser'
},
'plugins': [
'vue',
'@typescript-eslint'
],
'rules': {
'vue/multi-word-component-names': 'off',
'vue/object-curly-spacing': [2, 'always'],
'vue/html-closing-bracket-spacing': [2, {
'selfClosingTag': 'always'
}],
'vue/max-attributes-per-line': [2, {
'singleline': {
'max': 1
},
'multiline': {
'max': 1
}
}],
'semi': [2, 'never']
}
}
I had this problem on node v12.22.9.我在节点 v12.22.9 上遇到了这个问题。 By upgrading to v14.21.2, I no longer had the parsing error.
通过升级到 v14.21.2,我不再有解析错误。 You can upgrade/install with the command
您可以使用命令升级/安装
nvm install v14.21.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.