简体   繁体   中英

How to resolve "import/no-unresolved" in ESLint for import files! for javascript and nodejs

Eslint cannot find the file's location!

This is the error!

在此处输入图像描述

I was having this problem!

Eslint cannot find the file's location because the path of the file is not fully defined, we must specify them in the configuration file.

The reference exists and it works, the problem is that eslint cannot find it. I fix it as follows!

Unable to resolve the module path './Board'. note that Board does not have an extension, that's the problem. We just need to specify eslint how to resolve the extensions and voila.

在此处输入图像描述

I assume eslint installed and has problems integrating express node and react js projects

You can use the automatic configuration of eslint follow the steps and when it is installed configure your.eslint.json file add the description of settings

"settings": {
"import/resolver": {
  "node": {
    "extensions": [".js", ".jsx"],
    "moduleDirectory": ["node_modules", "src/"]
  }
}

}

.eslintrc.json the full file look like:

    {
  "env": {
    "browser": true,
    "es2021": true,
    "node": true
  },
  "extends": ["plugin:import/recommended", "plugin:react/recommended", "standard"],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react"],
  "rules": {
    "semi": [2, "always"],
    "comma-dangle": [
      "error",
      {
        "arrays": "only-multiline",
        "objects": "only-multiline",
        "imports": "only-multiline",
        "exports": "only-multiline",
        "functions": "only-multiline"
      }
    ],
    "space-before-function-paren": 0,
    "spaced-comment": [
      "error",
      "never",
      {
        "line": {
          "markers": ["/"],
          "exceptions": ["-", "+"]
        },
        "block": {
          "markers": ["!", "-", "+"],
          "exceptions": ["*"],
          "balanced": true
        }
      }
    ]
  },
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx"],
        "moduleDirectory": ["node_modules", "src/"]
      }
    }
  }
}

https://eslint.org/docs/user-guide/getting-started

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM