【问题标题】:Parsing error: Unexpected token prettier/prettier caused by "<!DOCTYPE html>"解析错误:由“<!DOCTYPE html>”引起的意外令牌更漂亮/更漂亮
【发布时间】:2021-02-26 07:01:02
【问题描述】:

我有这个使用 vue cli 创建的 vue 应用,我使用的版本是 vue2(带有 eslint 和 prettier)。

我可以运行npm run serve 并加载我的页面。但是在 Visual Studio Code 中,我注意到了这个错误:

{
    "resource": "/c:/vue/app2/public/index.html",
    "owner": "eslint",
    "code": {
        "value": "prettier/prettier",
        "target": {
            "$mid": 1,
            "external": "https://github.com/prettier/eslint-plugin-prettier#options",
            "path": "/prettier/eslint-plugin-prettier",
            "scheme": "https",
            "authority": "github.com",
            "fragment": "options"
        }
    },
    "severity": 4,
    "message": "Parsing error: Unexpected token",
    "source": "eslint",
    "startLineNumber": 1,
    "startColumn": 2,
    "endLineNumber": 1,
    "endColumn": 2
}

这是我的.eslintrc.js,它是在我创建应用程序时自动生成的,此后我没有对其进行任何更改。

module.exports = {  
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
  parserOptions: {
    ecmaVersion: 2020
  },
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off"
  }
};

我注意到错误实际上是指这一行。有谁知道这是怎么回事?

<!DOCTYPE html>

【问题讨论】:

    标签: eslint prettier prettier-eslint


    【解决方案1】:

    我遇到了类似的问题。这是由&lt;!DOCTYPE html&gt;引起的。

    修复很简单,我们需要在prettierrc 中指定一个解析器,虽然很明显:

    overrides:
      - files: '*.html'
        options:
          parser: 'html'
      - files: '*.component.html'
        options:
          parser: 'angular'
    

    之后,prettier 可以使用&lt;!DOCTYPE html&gt; 格式化文件。

    积分转到krave1986

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-21
      • 2021-04-06
      • 2020-02-13
      • 2019-08-24
      • 2021-03-24
      • 2021-06-22
      • 2017-05-23
      • 2014-03-04
      相关资源
      最近更新 更多