从子文件夹运行eslint时无法解析相对的模块路径

编程入门 行业动态 更新时间:2024-10-21 09:42:23
本文介绍了从子文件夹运行eslint时无法解析相对的模块路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我从仓库的根目录运行eslint时,一切运行正常,没有错误.

When I run eslint from the root folder of my repo everything runs fine, with no errors.

但是,当我从子文件夹运行时,会得到大量导入/无法解析的信息,而从根目录运行时不会发生这种情况:

But when I run from a subfolder I get a ton of import/no-unresolved that don't happen when I run from root:

/reporoot/subfolder0/subfolder1/MyFile.js 11:8 error Unable to resolve path to module 'foo' import/no-unresolved 11:8 error Missing file extension for "foo" import/extensions 14:97 error Unable to resolve path to module 'foo' import/no-unresolved 14:97 error Missing file extension for "foo" import/extensions

我怎么跑都没关系.例如:

Doesn't matter how I run. e.g.:

这将起作用:

cd /reporoot eslint .

所有这些命令将失败,并显示上面的错误:

All of these commands will fail with error shown above:

cd subfolder0 eslint .

eslint subfolder0

eslint /reporoot/subfolder0/subfolder1/MyFile.js

任何想法是什么问题,或有关如何解决它的想法?

Any idea what the issue is, or thoughts about how to fix it?

推荐答案

根据此GitHub问题.

尝试在您的 .eslintrc.json 中进行设置(如果不使用JSON,则将其转换为任何其他文件类型)

Try to set this in your .eslintrc.json (Or convert it to any other filetype if you don't use JSON)

"settings": { "import/resolver": { "node": { "extensions": [".js", ".jsx", ".ts", ".tsx"] } } }

如果上述方法不起作用,而您只是想摆脱这些错误,则只需添加以下内容即可:

If the above doesn't work and you just want to get rid of these errors just add this instead:

"settings": { "import/no-unresolved": 0, // Turn off "Unable to resolve path to module ..." error "import/extensions": 0 // Turn off "Missing file extension for ..." error }

无论如何,禁用它都没什么大不了的,因为众所周知,短绒棉因路径问题而闻名.

Disabling this is not that big of a deal anyway because linters are pretty well known for having problems with pathing.

更多推荐

从子文件夹运行eslint时无法解析相对的模块路径

本文发布于:2023-11-09 21:06:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   路径   模块   从子   eslint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!