1
votes

I'm trying to use eslint-import-resolver-babel-module but without success. Airbnb config uses "node" resolver, and it seems that only it is used.

Here's my config:

{
  "env": {
    "browser": true
  },
  "extends": "airbnb",
  "plugins": [
    "react",
    "jsx-a11y",
    "import"
  ],
  "rules": {
    "no-param-reassign": [2, { "props": false }]
  },
  "parser": "babel-eslint",
  "root": true,
  "settings": {
    "import/resolver": {
      "babel-module": {}
    }
  }
}

I get compiled config using this:

$ ./node_modules/.bin/eslint --print-config src/test.js > eslintconfig 2>&1 

Excerpt from the result:

...
"settings": {
    "import/resolver": {
      "node": {
        "extensions": [
          ".js",
          ".jsx",
          ".json"
        ]
      },
      "babel-module": {}
    },
...

Then I test using this command

$ cross-env DEBUG=eslint-plugin-import:resolver:* ./node_modules/.bin/eslint src/test.js > eslintdebug 2>&1

Output

Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node Resolving: client/test2 from: D:XXX\src\test.js
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node resolve threw error: { Error: Cannot find module 'client/test2' from 'D:XXX\src'
    at Function.module.exports [as sync] (D:XXX\node_modules\resolve\lib\sync.js:40:15)
    at Object.exports.resolve (D:XXX\node_modules\eslint-import-resolver-node\index.js:18:28)
    at v2 (D:XXX\node_modules\eslint-module-utils\resolve.js:79:23)
    at withResolver (D:XXX\node_modules\eslint-module-utils\resolve.js:84:16)
    at fullResolve (D:XXX\node_modules\eslint-module-utils\resolve.js:101:22)
    at relative (D:XXX\node_modules\eslint-module-utils\resolve.js:46:10)
    at resolve (D:XXX\node_modules\eslint-module-utils\resolve.js:172:12)
    at checkSourceValue (D:XXX\node_modules\eslint-plugin-import\lib\rules\no-unresolved.js:29:50)
    at checkSourceValue (D:XXX\node_modules\eslint-module-utils\moduleVisitor.js:29:5)
    at EventEmitter.checkSource (D:XXX\node_modules\eslint-module-utils\moduleVisitor.js:34:5) code: 'MODULE_NOT_FOUND' }
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node Resolving: client/test2 from: D:XXX\src\test.js
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node resolve threw error: { Error: Cannot find module 'client/test2' from 'D:XXX\src'
    at Function.module.exports [as sync] (D:XXX\node_modules\resolve\lib\sync.js:40:15)
    at Object.exports.resolve (D:XXX\node_modules\eslint-import-resolver-node\index.js:18:28)
    at v2 (D:XXX\node_modules\eslint-module-utils\resolve.js:79:23)
    at withResolver (D:XXX\node_modules\eslint-module-utils\resolve.js:84:16)
    at fullResolve (D:XXX\node_modules\eslint-module-utils\resolve.js:101:22)
    at relative (D:XXX\node_modules\eslint-module-utils\resolve.js:46:10)
    at resolve (D:XXX\node_modules\eslint-module-utils\resolve.js:172:12)
    at resolveImportType (D:XXX\node_modules\eslint-plugin-import\lib\core\importType.js:74:65)
    at reportIfMissing (D:XXX\node_modules\eslint-plugin-import\lib\rules\no-extraneous-dependencies.js:74:32)
    at EventEmitter.ImportDeclaration (D:XXX\node_modules\eslint-plugin-import\lib\rules\no-extraneous-dependencies.js:144:9) code: 'MODULE_NOT_FOUND' }
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node Resolving: client/test2 from: D:XXX\src\test.js
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node resolve threw error: { Error: Cannot find module 'client/test2' from 'D:XXX\src'
    at Function.module.exports [as sync] (D:XXX\node_modules\resolve\lib\sync.js:40:15)
    at Object.exports.resolve (D:XXX\node_modules\eslint-import-resolver-node\index.js:18:28)
    at v2 (D:XXX\node_modules\eslint-module-utils\resolve.js:79:23)
    at withResolver (D:XXX\node_modules\eslint-module-utils\resolve.js:84:16)
    at fullResolve (D:XXX\node_modules\eslint-module-utils\resolve.js:101:22)
    at relative (D:XXX\node_modules\eslint-module-utils\resolve.js:46:10)
    at resolve (D:XXX\node_modules\eslint-module-utils\resolve.js:172:12)
    at EventEmitter.ImportDeclaration (D:XXX\node_modules\eslint-plugin-import\lib\rules\no-duplicates.js:37:52)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:191:7) code: 'MODULE_NOT_FOUND' }
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node Resolving: client/test2 from: D:XXX\src\test.js
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node resolve threw error: { Error: Cannot find module 'client/test2' from 'D:XXX\src'
    at Function.module.exports [as sync] (D:XXX\node_modules\resolve\lib\sync.js:40:15)
    at Object.exports.resolve (D:XXX\node_modules\eslint-import-resolver-node\index.js:18:28)
    at v2 (D:XXX\node_modules\eslint-module-utils\resolve.js:79:23)
    at withResolver (D:XXX\node_modules\eslint-module-utils\resolve.js:84:16)
    at fullResolve (D:XXX\node_modules\eslint-module-utils\resolve.js:101:22)
    at relative (D:XXX\node_modules\eslint-module-utils\resolve.js:46:10)
    at resolve (D:XXX\node_modules\eslint-module-utils\resolve.js:172:12)
    at EventEmitter.checkFileExtension (D:XXX\node_modules\eslint-plugin-import\lib\rules\extensions.js:81:50)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:191:7) code: 'MODULE_NOT_FOUND' }
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node Resolving: client/test2 from: D:XXX\src\test.js
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node resolve threw error: { Error: Cannot find module 'client/test2' from 'D:XXX\src'
    at Function.module.exports [as sync] (D:XXX\node_modules\resolve\lib\sync.js:40:15)
    at Object.exports.resolve (D:XXX\node_modules\eslint-import-resolver-node\index.js:18:28)
    at v2 (D:XXX\node_modules\eslint-module-utils\resolve.js:79:23)
    at withResolver (D:XXX\node_modules\eslint-module-utils\resolve.js:84:16)
    at fullResolve (D:XXX\node_modules\eslint-module-utils\resolve.js:101:22)
    at relative (D:XXX\node_modules\eslint-module-utils\resolve.js:46:10)
    at resolve (D:XXX\node_modules\eslint-module-utils\resolve.js:172:12)
    at Function.ExportMap.get (D:XXX\node_modules\eslint-plugin-import\lib\ExportMap.js:281:38)
    at checkDefault (D:XXX\node_modules\eslint-plugin-import\lib\rules\no-named-as-default.js:25:41)
    at emitOne (events.js:101:20) code: 'MODULE_NOT_FOUND' }
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node Resolving: client/test2 from: D:XXX\src\test.js
Sun, 06 Aug 2017 14:16:33 GMT eslint-plugin-import:resolver:node resolve threw error: { Error: Cannot find module 'client/test2' from 'D:XXX\src'
    at Function.module.exports [as sync] (D:XXX\node_modules\resolve\lib\sync.js:40:15)
    at Object.exports.resolve (D:XXX\node_modules\eslint-import-resolver-node\index.js:18:28)
    at v2 (D:XXX\node_modules\eslint-module-utils\resolve.js:79:23)
    at withResolver (D:XXX\node_modules\eslint-module-utils\resolve.js:84:16)
    at fullResolve (D:XXX\node_modules\eslint-module-utils\resolve.js:101:22)
    at relative (D:XXX\node_modules\eslint-module-utils\resolve.js:46:10)
    at resolve (D:XXX\node_modules\eslint-module-utils\resolve.js:172:12)
    at Function.ExportMap.get (D:XXX\node_modules\eslint-plugin-import\lib\ExportMap.js:281:38)
    at EventEmitter.handleImportDefault (D:XXX\node_modules\eslint-plugin-import\lib\rules\no-named-as-default-member.js:35:45)
    at emitOne (events.js:101:20) code: 'MODULE_NOT_FOUND' }

[4mD:XXX\src\test.js[24m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-unresolved[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-extraneous-dependencies[22m
  [2m1:1[22m   [31merror[39m  'client' should be listed in the project's dependencies. Run 'npm i -S client' to add it  [2mimport/no-extraneous-dependencies[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-duplicates[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/extensions[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-named-as-default[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-named-as-default-member[22m
  [2m1:8[22m   [31merror[39m  'test' is defined but never used                                                          [2mno-unused-vars[22m
  [2m1:18[22m  [31merror[39m  Unable to resolve path to module 'client/test2'                                           [2mimport/no-unresolved[22m
  [2m1:18[22m  [31merror[39m  Missing file extension for "client/test2"                                                 [2mimport/extensions[22m

[31m[1m✖ 10 problems (10 errors, 0 warnings)
[22m[39m

And here as you can see only eslint-plugin-import:resolver:node is used, no sight of eslint-plugin-import:resolver:babel-module.

I've also tried this:

"settings": {
    "import/resolver": "babel-module"
}

But results are even worse:

[4mD:XXX\src\test.js[24m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-unresolved[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-extraneous-dependencies[22m
  [2m1:1[22m   [31merror[39m  'client' should be listed in the project's dependencies. Run 'npm i -S client' to add it  [2mimport/no-extraneous-dependencies[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-duplicates[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/extensions[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-named-as-default[22m
  [2m1:1[22m   [31merror[39m  Resolve error: undefined                                                                  [2mimport/no-named-as-default-member[22m
  [2m1:8[22m   [31merror[39m  'test' is defined but never used                                                          [2mno-unused-vars[22m
  [2m1:18[22m  [31merror[39m  Unable to resolve path to module 'client/test2'                                           [2mimport/no-unresolved[22m
  [2m1:18[22m  [31merror[39m  Missing file extension for "client/test2"                                                 [2mimport/extensions[22m

[31m[1m✖ 10 problems (10 errors, 0 warnings)
[22m[39m

Dependencies versions:

$ npm ls babel-plugin-module-resolver eslint-import-resolver-babel-module eslint-config-airbnb eslint-plugin-import eslint
[email protected] D:\XXX
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

How to override plugin settings of parent config?

1

1 Answers

1
votes

It turns out eslint-plugin-import takes a list of resolvers, and checks them one by one until one of them resolves the file correctly.