WebStorm ESLint中出现ESLint错误:解析导入模块中的错误

问题描述 投票:1回答:1

这是我在这里看到的进口物:

import { HttpClient } from '@angular/common/http';
import { ConfirmationService, MessageService } from "primeng/api";

我看到的错误是

ESLint: Parse errors in imported module '@angular/common/http': Cannot read property 'name' of undefined (undefined:undefined)(import/namespace)

ESLint: Parse errors in imported module 'primeng/api': Cannot read property 'name' of undefined (undefined:undefined)(import/namespace)

这是我的.eslint.json:

{
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jasmine": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "plugin:jasmine/recommended"
  ],
  "settings": {
    "import/parsers": { "@typescript-eslint/parser": [".ts"] },
    "import/resolver": {
      "typescript": {
        "directory": "./"
      }
    }
  },
  "overrides": [
    {
      "files": ["*.ts"],
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "allowImportExportEverywhere": true,
        "ecmaVersion": 2020,
        "project": "./tsconfig.json",
        "sourceType": "module",
        "ecmaFeatures": {
          "modules": true,
          "arrowFunctions": true,
          "classes": true
        }
      },
      "plugins": [
        "@typescript-eslint",
        "@angular-eslint",
        "@typescript-eslint/tslint",
        "import",
        "jsdoc",
        "prefer-arrow",
        "jasmine"
      ],
      "rules": {
        "@angular-eslint/component-class-suffix": "error",
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "app",
            "style": "kebab-case"
          }
        ],
        "@angular-eslint/contextual-lifecycle": "error",
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "app",
            "style": "camelCase"
          }
        ],
        "@angular-eslint/no-conflicting-lifecycle": "error",
        "@angular-eslint/no-host-metadata-property": "error",
        "@angular-eslint/no-input-rename": "error",
        "@angular-eslint/no-output-native": "error",
        "@angular-eslint/no-output-on-prefix": "error",
        "@angular-eslint/no-output-rename": "error",
        "@angular-eslint/no-outputs-metadata-property": "error",
        "@typescript-eslint/adjacent-overload-signatures": "error",
        "@typescript-eslint/array-type": "off",
        "@typescript-eslint/ban-types": "error",
        "@typescript-eslint/class-name-casing": "error",
        "@typescript-eslint/consistent-type-assertions": "error",
        "@typescript-eslint/consistent-type-definitions": "error",
        "@typescript-eslint/explicit-member-accessibility": [
          "off",
          {
            "accessibility": "explicit"
          }
        ],
        "@typescript-eslint/indent": "off",
        "@typescript-eslint/interface-name-prefix": "off",
        "@typescript-eslint/member-delimiter-style": [
          "off",
          {
            "multiline": {
              "delimiter": "none",
              "requireLast": true
            },
            "singleline": {
              "delimiter": "semi",
              "requireLast": false
            }
          }
        ],
        "@typescript-eslint/member-ordering": [
          "error",
          {
            "default": ["static-field", "instance-field", "static-method", "instance-method"]
          }
        ],
        "@typescript-eslint/no-empty-function": "off",
        "@typescript-eslint/no-empty-interface": "error",
        "@typescript-eslint/no-explicit-any": "error",
        "@typescript-eslint/no-inferrable-types": "error",
        "@typescript-eslint/no-misused-new": "error",
        "@typescript-eslint/no-namespace": "error",
        "@typescript-eslint/no-non-null-assertion": "error",
        "@typescript-eslint/no-parameter-properties": "off",
        "@typescript-eslint/no-use-before-define": "error",
        "@typescript-eslint/no-var-requires": "error",
        "@typescript-eslint/prefer-for-of": "error",
        "@typescript-eslint/prefer-function-type": "error",
        "@typescript-eslint/prefer-namespace-keyword": "error",
        "@typescript-eslint/prefer-readonly": "error",
        "@typescript-eslint/quotes": ["error", "single"],
        "@typescript-eslint/semi": ["error", "always"],
        "@typescript-eslint/triple-slash-reference": "error",
        "@typescript-eslint/tslint/config": [
          "error",
          {
            "rules": {
              "directive-class-suffix": true,
              "jsdoc-format": true,
              "lines-between-class-members": true,
              "no-reference-import": true,
              "no-unused-variable": true,
              "template-banana-in-box": true,
              "template-no-negated-async": true,
              "use-lifecycle-interface": true,
              "use-pipe-transform-interface": true
            }
          }
        ],
        "@typescript-eslint/type-annotation-spacing": "error",
        "@typescript-eslint/unified-signatures": "error",
        "array-bracket-spacing": ["error", "never"],
        "arrow-body-style": "error",
        "arrow-parens": ["off", "as-needed"],
        "block-spacing": "error",
        "brace-style": "error",
        "camelcase": "error",
        "comma-dangle": "off",
        "comma-spacing": "error",
        "comma-style": ["error", "last"],
        "complexity": "off",
        "constructor-super": "error",
        "curly": "error",
        "dot-notation": "error",
        "eol-last": "off",
        "eqeqeq": ["error", "smart"],
        "getter-return": "error",
        "guard-for-in": "error",
        "id-blacklist": [
          "error",
          "any",
          "Number",
          "number",
          "String",
          "string",
          "Boolean",
          "boolean",
          "Undefined",
          "undefined"
        ],
        "id-match": "error",
        "import/no-deprecated": "off",
        "import/order": "error",
        "jsdoc/no-types": "error",
        "linebreak-style": "off",
        "lines-between-class-members": [
          "error",
          "always",
          {
            "exceptAfterSingleLine": true
          }
        ],
        "padding-line-between-statements": [
          "error",
          {
            "blankLine": "always",
            "prev": "*",
            "next": "return"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "if"
          },
          {
            "blankLine": "always",
            "prev": "if",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "block-like",
            "next": "block-like"
          },
          {
            "blankLine": "always",
            "prev": "try",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "try"
          },
          {
            "blankLine": "always",
            "prev": "do",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "do"
          },
          {
            "blankLine": "always",
            "prev": "const",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "while",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "while"
          },
          {
            "blankLine": "always",
            "prev": "for",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "for"
          },
          {
            "blankLine": "always",
            "prev": "const",
            "next": "*"
          },
          {
            "blankLine": "never",
            "prev": "const",
            "next": "const"
          },
          {
            "blankLine": "always",
            "prev": "let",
            "next": "*"
          },
          {
            "blankLine": "never",
            "prev": "let",
            "next": "let"
          },
          {
            "blankLine": "always",
            "prev": "import",
            "next": "*"
          },
          {
            "blankLine": "never",
            "prev": "import",
            "next": "import"
          },
          {
            "blankLine": "never",
            "prev": "export",
            "next": "export"
          },
          {
            "blankLine": "always",
            "prev": "export",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "continue"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "throw"
          },
          {
            "blankLine": "always",
            "prev": "multiline-const",
            "next": "*"
          },
          {
            "blankLine": "always",
            "prev": "*",
            "next": "multiline-const"
          }
        ],
        "max-classes-per-file": "error",
        "max-len": [
          "error",
          {
            "code": 140
          }
        ],
        "new-parens": "error",
        "newline-per-chained-call": "off",
        "no-await-in-loop": "error",
        "no-bitwise": "error",
        "no-caller": "error",
        "no-cond-assign": "error",
        "no-console": [
          "error",
          {
            "allow": [
              "log",
              "dirxml",
              "warn",
              "error",
              "dir",
              "timeLog",
              "assert",
              "clear",
              "count",
              "countReset",
              "group",
              "groupCollapsed",
              "groupEnd",
              "table",
              "Console",
              "markTimeline",
              "profile",
              "profileEnd",
              "timeline",
              "timelineEnd",
              "timeStamp",
              "context"
            ]
          }
        ],
        "no-constant-condition": "error",
        "no-debugger": "error",
        "no-else-return": "error",
        "no-empty": "error",
        "no-eval": "error",
        "no-extra-semi": "error",
        "no-fallthrough": "error",
        "no-implicit-coercion": "error",
        "no-invalid-this": "error",
        "no-lonely-if": "error",
        "no-irregular-whitespace": "off",
        "no-magic-numbers": "error",
        "no-mixed-operators": "error",
        "no-multiple-empty-lines": "error",
        "no-multi-assign": "error",
        "no-new": "error",
        "no-new-wrappers": "error",
        "no-param-reassign": "error",
        "no-restricted-imports": ["error", "rxjs/Rx"],
        "no-return-assign": "error",
        "no-return-await": "error",
        "no-sequences": "error",
        "no-shadow": [
          "error",
          {
            "hoist": "all"
          }
        ],
        "no-throw-literal": "error",
        "no-trailing-spaces": "error",
        "no-undef-init": "error",
        "no-underscore-dangle": "error",
        "no-unmodified-loop-condition": "error",
        "no-unreachable": "error",
        "no-restricted-exports": [
          "error",
          {
            "restrictedNamedExports": ["default"]
          }
        ],
        "no-unsafe-finally": "error",
        "no-unused-expressions": "error",
        "no-unused-labels": "error",
        "no-unused-vars": "error",
        "no-useless-catch": "error",
        "no-useless-return": "error",
        "no-var": "error",
        "object-shorthand": "error",
        "one-var": ["error", "never"],
        "prefer-arrow/prefer-arrow-functions": "error",
        "prefer-const": "error",
        "prefer-destructuring": "error",
        "prefer-rest-params": "error",
        "prefer-spread": "error",
        "prefer-template": "error",
        "quote-props": ["error", "as-needed"],
        "radix": "error",
        "require-await": "error",
        "space-before-function-paren": ["error", "never"],
        "space-in-parens": ["error", "never"],
        "spaced-comment": "error",
        "use-isnan": "error",
        "valid-typeof": "off",
        "yoda": "error"
      }
    },
    {
      "files": ["*.component.html"],
      "parser": "@angular-eslint/template-parser",
      "plugins": ["@angular-eslint/template"],
      "rules": {
        // ORIGINAL tslint.json -> "template-banana-in-box": true,
        "@angular-eslint/template/banana-in-a-box": "error",

        // ORIGINAL tslint.json -> "template-no-negated-async": true,
        "@angular-eslint/template/no-negated-async": "error"
      }
    },
    {
      "files": ["*.component.ts"],
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "ecmaVersion": 2020,
        "sourceType": "module"
      },
      "plugins": ["@angular-eslint/template"],
      "processor": "@angular-eslint/template/extract-inline-html"
    }
  ]
}

这是我的.tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@library/*": ["src/app/projects/library/*"],
      "@agreement/*": ["src/app/projects/agreement/*"],
      "@customer/*": ["src/app/projects/customer/*"],
      "@carrier/*": ["src/app/projects/carrier/*"],
      "@ltl/*": ["src/app/projects/ltl/*"],
      "@rail/*": ["src/app/projects/rail/*"]
    },
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "ESNext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2018", "dom"],
    "emitDecoratorMetadata": false
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  },
  "exclude": ["node_modules"]
}

我稍微玩了一下parserOptions。您看到的是我尝试过的内容,但没有帮助。我已经搜索过Google,但没有找到任何东西。这可能是WebStorm的特定问题,因为我无法使用VSCode复制它。

让我知道您还有什么需要帮助我的。我可以提供WebStorm设置的屏幕截图。任何帮助,将不胜感激。

javascript angular typescript webstorm eslint
1个回答
1
投票

可能与此问题有关:https://github.com/typescript-eslint/typescript-eslint/issues/1746

您应该将打字稿更新为3.8或将打字稿的eslint降级为2.23.0

@编辑我遇到了同样的问题,在将typescript-eslint降级后,错误消失了,但是我的构建脚本仍然崩溃。我想我们将不得不等待@ typescript-eslint / parser更新

@ Edit2您应该尝试将这3个卷装降级为2.23.0,尝试使用纱线分辨率:

"@typescript-eslint/eslint-plugin": "2.23.0",
"@typescript-eslint/parser": "2.23.0",
"@typescript-eslint/typescript-estree": "2.23.0"

经过几天的努力,它实际上对我有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.