tleunen / eslint-import-resolver-babel-module

Custom eslint resolve for babel-plugin-module-resolver
https://github.com/tleunen/babel-plugin-module-resolver
MIT License
248 stars 31 forks source link

How to config custom root? #105

Open phakphumi opened 5 years ago

phakphumi commented 5 years ago

I would like to use custom root, so I can import file like this import A from ‘/components/A;

Unfortunately, eslint-plugin-import can’t figure out that I mention to custom root.

I turn on import/no-relative-parent-imports. When I import the path like import { UserContext } from '/contexts/UserContext'; It shows me an error Relative imports from parent directories are not allowed. Please either pass what you're importing through at runtime (dependency injection), move `useAuthorization.js` to same directory as `/contexts/UserContext` or consider making `/contexts/UserContext` a package.eslint(import/no-relative-parent-imports)

What did I miss? or it just can’t use like this.

.babelrc

{
  "plugins": [
    ["module-resolver", {
      "root": ["./"]
    }]
  ]
}

.eslintrc

{
  "extends": "airbnb",
  "rules": {
    "import/no-relative-parent-imports": "error"
  },
  "settings": {
    "import/resolver": {
      "babel-module": {}
    }
  }
}
michaelnagy commented 5 years ago

I have the same question above, I can't make it work and there's no clear example in the docs.

michaelnagy commented 5 years ago

I found out that the plugin in the newer versions reads config from .babelrc, as stated in this issue #95