![](/img/trans.png)
[英]how to resolve import/no-unresolved with setup of eslint in webpack 4
[英]How to resolve "import/no-unresolved" in ESLint for import files! for javascript and nodejs
我遇到了这个问题!
Eslint 找不到文件的位置,因为文件的路径没有完全定义,我们必须在配置文件中指定它们。
引用存在并且有效,问题是 eslint 找不到它。 我修复它如下!
无法解析模块路径“./Board”。 请注意,Board 没有扩展,这就是问题所在。 我们只需要指定 eslint 如何解析扩展,瞧。
我假设 eslint 已安装并且在集成 express node 和 react js 项目时遇到问题
您可以按照步骤使用 eslint 的自动配置,并在安装时配置 your.eslint.json 文件添加设置说明
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx"],
"moduleDirectory": ["node_modules", "src/"]
}
}
}
.eslintrc.json完整文件如下所示:
{
"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/"]
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.