首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >eslint在声明文件上抛出import/no-未解决的错误

eslint在声明文件上抛出import/no-未解决的错误
EN

Stack Overflow用户
提问于 2020-12-02 00:50:57
回答 2查看 3.4K关注 0票数 3

Eslint抛出导入错误: import /no-导入typescript声明文件时未解析。我正在使用lerna进行monorepo。相关声明文件导入。导入文件下面是app.d.ts文件。

我可以在下面的配置中添加"import/ignore":".d.ts“,它可以解决这个错误,但我正在寻找一个不同于此的解决方案。

代码语言:javascript
运行
复制
// types
import { Theme } from '@typings/app';

我的.eslintrc.js配置文件:

代码语言:javascript
运行
复制
module.exports = {
  parser: "@typescript-eslint/parser",
  extends: [
    "airbnb",
    "plugin:@typescript-eslint/recommended",
    "prettier",
    "prettier/react"
  ],
  plugins: ["react", "jsx-a11y", "react-hooks", "sprinklr"],
  env: {
    browser: true,
    node: true,
    es6: true
  },
  globals: {
    define: true,
    require: true
  },
  rules: {
    strict: [2, "never"],
    "no-multi-spaces": 0,
    "spaced-comment": 0,
    "no-multi-assign": 0,
    //Import rules
    "import/extensions": [
      2,
      "ignorePackages",
      {
        js: "never",
        jsx: "never",
        mjs: "never",
        ts: "never",
        tsx: "never"
      }
    ],
    "import/no-unresolved": 2,
    "import/no-extraneous-dependencies": 0,
    "import/no-named-as-default-member": 0,
    "import/prefer-default-export": 0,
    //Keeping below till idea supports these codestyles
    "object-curly-spacing": 0,

    //ts related rules
    "indent": 0,
    "@typescript-eslint/indent": 0,
    "@typescript-eslint/explicit-member-accessibility": 0,
    "@typescript-eslint/camelcase": 0,
    "import/no-webpack-loader-syntax": 0,
    "@typescript-eslint/prefer-interface": 0,
    "import/no-cycle": 1,
    "react/prop-types": 0,
    "@typescript-eslint/ban-ts-ignore": 1, //Remove after ts adoption increases
    "@typescript-eslint/explicit-function-return-type": [1, {
      "allowTypedFunctionExpressions": true
    }],
    "@typescript-eslint/no-this-alias": 0,
    "sprinklr/no-logic-i18n-template-literal": 2,
  },
  parserOptions: {
    sourceType: "module",
    ecmaVersion: 6,
    ecmaFeatures: {
      globalReturn: true,
      jsx: true
    },
    allowImportExportEverywhere: true
  },
  settings: {
    "import/extensions": [".js", ".jsx", ".mjs", ".ts", ".tsx"],
    "import/resolver": {
      webpack: {
        config: {
          resolve: {
            extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
          },
        },
      },
    },
    "react": {
      version: "detect",
    },
  },
  overrides: [
    {
      files: ["**/*.spec.*", "**/*.test.*", "**/*.d.ts"],
      env: {
        jest: true
      },
      globals: {
        // Enzyme globals
        mount: true,
        shallow: true,
        render: true
      },
      rules: {
        "@typescript-eslint/no-var-requires": 0,
        "@typescript-eslint/no-empty-function": 0,
      }
    }
  ]
};
EN

Stack Overflow用户

发布于 2020-12-30 16:36:53

提高你的.eslintrc

代码语言:javascript
运行
复制
...,
// parser: "@typescript-eslint/parser", -- not needed, "plugin:@typescript-eslint/recommended" has added
extends: [
  "airbnb",
  "plugin:import/typescript", // added
  "plugin:@typescript-eslint/recommended",
  "prettier",
  "prettier/@typescript-eslint" // added
  "prettier/react"
],
plugins: [
  // "react", -- not needed, airbnb has covered
  // "jsx-a11y", -- not needed, airbnb has covered
  // "react-hooks", -- not needed, airbnb has covered
  "sprinklr"
],
env: {
  browser: true,
  // node: true, -- not needed, airbnb has covered
  // es6: true, -- not needed, airbnb has covered
  amd: true // add define and require
},
globals: {
  // define: true, -- not needed, use amd env
  // require: true -- not needed, use amd env
},
...,
parserOptions: {
  // sourceType: "module", -- not needed, airbnb has covered
  // ecmaVersion: 6, -- not needed, airbnb has covered
  // ecmaFeatures: { -- not needed, airbnb has covered
  //   globalReturn: true, -- not needed, airbnb has covered
  //   jsx: true -- not needed, airbnb has covered
  // },
  allowImportExportEverywhere: true
},
...,
settings: {
  ...,
  // "react": { -- not needed, airbnb has covered
  //   version: "detect", -- not needed, airbnb has covered
  // },
  ...,
},

此外,您可能需要查看"plugin:import/typescript“在此处设置的内容:https://github.com/benmosher/eslint-plugin-import/blob/master/config/typescript.js

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65094870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档