【问题标题】:Prettier AutoFormatting error for typescript and javascript mixed project打字稿和 javascript 混合项目的更漂亮的自动格式化错误
【发布时间】:2020-05-02 23:59:35
【问题描述】:

我正在将打字稿添加到现有的 javascript 项目。这是一个大型项目,所以我决定将项目逐步转换为打字稿。

这是我的 eslintrc.js 文件

module.exports = {
  parser: '@typescript-eslint/parser', // Specifies the ESLint parser
  extends: [
    'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
    'airbnb-typescript/base', // Airbnb style guide
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:import/typescript',
    'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
    'prettier/@typescript-eslint' // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
  ],
  parserOptions: {
    ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
    sourceType: 'module' // Allows for the use of imports
  },
  settings: {
    'import/resolver': {
      node: {
        extensions: ['.js', '.jsx', '.ts', '.tsx']
      }
    }
  },
  rules: {
    // some rules here
  },
  plugins: ['prettier']
};

问题在于保存,更漂亮的应该格式化我的代码。但它没有

这是我的 Prettier 日志的输出

["ERROR" - 12:34:20 PM] Error formatting document.
Failed to load plugin '@typescript-eslint' declared in 'CLIOptions': Cannot find module '@typescript-eslint/eslint-plugin'

我尝试运行npm install @typescript-eslint --save-dev。但没有运气

如何优化我的 eslintrc 来解决这个问题。 提醒:我应该能够将此配置与 typescript 和 javascript 一起使用。

【问题讨论】:

    标签: javascript typescript prettier eslint-config-airbnb


    【解决方案1】:

    禁用 vscode 更漂亮的扩展解决了我的问题。该扩展与我更漂亮的设置相冲突。希望扩展开发团队能尽快解决这个问题。

    【讨论】:

      猜你喜欢
      • 2020-11-02
      • 2012-03-07
      • 2011-01-07
      • 2019-06-07
      • 2021-09-23
      • 2020-04-28
      • 2022-01-11
      • 1970-01-01
      相关资源
      最近更新 更多