【问题标题】:ESLint linting node_modulesESLint linting node_modules
【发布时间】:2020-12-28 00:10:27
【问题描述】:

我一直在尝试谷歌搜索上的所有结果作为可能的解决方案,但到目前为止没有任何运气。

每当我在我的 vue 项目(使用 vue cli 创建)上运行 npm run vue-cli-service serve --port 1024 时,我都会收到来自 node_modules 的错误

4111:10 Type alias 'MergeList' circularly references itself.
    4109 |     @hidden
    4110 |     */
  > 4111 |     type MergeList<O, Path extends List<Key>, O1 extends object, depth extends Depth, I extends Iteration = IterationOf<'0'>> = O extends object ? O extends (infer A)[] ? MergeList<A, Path, O1, depth, I>[] : Pos<I> extends Length<Path> ? OMerge<O, O1, depth> : {
         |          ^
    4112 |         [K in keyof O]: K extends Path[Pos<I>] ? MergeList<O[K], Path, O1, depth, Next<I>> : O[K];
    4113 |     } & {} : O;
    4114 |     /**

所有错误看起来都来自一个文件夹:ts-toolbelt。最终结果可以在这里看到:pastebin

这是我的.eslintrc

module.exports = {
  root: true,

  env: {
    node: true,
  },

  extends: [
    'plugin:vue/essential',
    '@vue/airbnb',
    '@vue/typescript',
  ],

  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    "import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
    'import/no-cycle': 'off',
  },

  parserOptions: {
    parser: '@typescript-eslint/parser',
    exclude: [
      "node_modules"
    ]
  },

  overrides: [
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)'
      ],
      env: {
        jest: true
      }
    }
  ],
};

.eslintignore

node_modules/
public/
bin/
build/

vue.config.js

module.exports = {
  transpileDependencies: [
    'vuetify',
  ],
  pwa: {
    workboxOptions: {
      skipWaiting: true,
    },
  },
};

感谢您抽出宝贵时间提供帮助

【问题讨论】:

  • 如果你执行vue-cli-service test:unit,你会得到同样的错误(Type alias 'MergeList' circularly references itself.)吗?
  • 是的,效果很好。仅当我实际运行 npm run serve 时才会发生
  • 作为一种解决方法,您可以在服务运行时跳过eslint 插件:vue-cli-service serve --skip-plugins @vue/cli-plugin-eslint

标签: vue.js eslint eslintrc eslintignore


【解决方案1】:

.eslintrc.js 中使用ignorePatterns

module.exports = {
  // ...
  ignorePatterns: ["**/node_modules/**"] // THIS WORKS!
};

【讨论】:

    【解决方案2】:

    我认为.eslintignore应该是:

    node_modules
    public
    bin
    build
    

    【讨论】:

    • 感谢您的评论,但仍然遇到同样的错误。仅在 ts-toolbelt 文件夹中
    • 添加到你忽略的文件然后
    • 尝试使用node_modules/ts-toolbelt/out/index.d.ts 直接添加文件夹,但该文件夹中仍然出现相同的错误
    • 如果你只删除.eslintIgnore会发生什么?
    • 同理。无论如何都会继续 linting eslint
    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 2018-09-03
    • 2018-08-22
    • 2020-09-25
    • 2020-03-23
    • 1970-01-01
    • 2020-05-28
    • 2023-03-25
    相关资源
    最近更新 更多