javascript - Unable to resolve relative module paths when eslint run from sub-folder - Stack Overflow

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

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.:

This will work:

cd /reporoot
eslint .

All of these mands will fail with error shown above:

cd subfolder0
eslint .

or

eslint subfolder0

or

eslint /reporoot/subfolder0/subfolder1/MyFile.js

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

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.:

This will work:

cd /reporoot
eslint .

All of these mands will fail with error shown above:

cd subfolder0
eslint .

or

eslint subfolder0

or

eslint /reporoot/subfolder0/subfolder1/MyFile.js

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

Share Improve this question edited May 9, 2019 at 20:07 griffin2000 asked May 9, 2019 at 17:25 griffin2000griffin2000 77910 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

This is probably a problem with absolute paths in your imports according to this GitHub issue.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744375478a4571165.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信