Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Re-Opening Issue 36 #40

Closed
machineghost opened this issue Feb 5, 2017 · 7 comments
Closed

Re-Opening Issue 36 #40

machineghost opened this issue Feb 5, 2017 · 7 comments

Comments

@machineghost
Copy link

machineghost commented Feb 5, 2017

I originally created issue #36, but it was closed without resolving my underlying problem. While I'm sure it solved a different issue, my issue (even after installing the latest version, 3.10.10) unfortunately remains.

One again here are my relevant bits from my relevant files ...

.eslintrc:

{
  "extends": "airbnb",
  "parser": "babel-eslint",
  "plugins": [
    "babel"
  ],
  "settings": {
    "import/resolver": {
      "babel-module": {
        "root": ["./src"],
        "alias": {
          "components": "./frontend/src/components",
          "state": "./frontend/src/state",
          "test": "./frontend/test"
        }
      }
    }
  }
}

.babelrc

{
  "plugins": [
    "transform-object-rest-spread",
    ["module-resolver", {
      "root": ["./frontend/src"],
      "alias": {
        "components": "./frontend/src/components",
        "state": "./frontend/src/state",
        "test": "./frontend/test"
      }
    }]
  ],
  "env": {
    "development": {
      "presets": [
        "es2015",
        "decorators-legacy",
        "react",
        "babel-react-render-defender"
      ]
    },
    "production": {
      "presets": [
        "es2015",
        "decorators-legacy",
        "react"
      ]
    }
  }
}

However, when I ESlint a file (a file that can successfully import module-resolver-resolved paths using Babel just fine) I get:

7:26 error Unable to resolve path to module 'components/ui/countryPicker/CountryGroup' import/no-unresolved

... even though src/components/ui/countryPicker/CountryGroup exists, and even though I have both "root": ["./src"], and "alias": {"components": "./frontend/src/components", in both my .babelrc and my .eslintrc.

Any help resolving this would be appreciated. As before, unfortunately I can't share a repository of my entire project (because I'd be fired if I did), but if there is any other relevant information (debug logs, copies of other config files, etc.) I'd be happy to provide it.

@tleunen
Copy link
Owner

tleunen commented Feb 5, 2017

Sorry about that @machineghost. Let's find out what is causing your issue :)

First, let's remove the alias/root config set in your eslint config. The one from the babel plugin will be used anyway.

Then it seems you can replace your babel config with this one:

    ["module-resolver", {
      "root": ["./frontend/src"],
      "alias": {
        "test": "./frontend/test"
      }
    }]

Having both root and alias shouldn't conflict, but it will be easier to remove any extras :)

Do you think you could build a small repo with your eslint and babel config, while replacing your files by dummy files? (Only the relevant paths are fine. The content doesn't really matter)

@machineghost
Copy link
Author

https://github.com/machineghost/eslint-import-resolver-babel-module-issues-40

Run npm run demo to see the failure (and a few not relevant ones):

/Users/jwalker/eslint-import-resolver-babel-module-issues-  40/src/components/ui/countryPicker/index.jsx
  1:1   error  'components' should be listed in the project's dependencies. Run 'npm i -S components' to add it  import/no-extraneous-dependencies
  1:20  error  Unable to resolve path to module 'components/ui/countryPicker/CountryPicker'                      import/no-unresolved
  1:20  error  Missing file extension for "components/ui/countryPicker/CountryPicker"                              import/extensions

@tleunen
Copy link
Owner

tleunen commented Feb 6, 2017

In your demo, the root config is not properly set. It should be "root": ["./src"],

@machineghost
Copy link
Author

Sorry about that (side effect of simplifying a more complex project). I've corrected the demo repo.

@tleunen
Copy link
Owner

tleunen commented Feb 6, 2017

I got it working yesterday when I tried so I thought it was the only issue.

After removing the old plugins (module-alias) and upgrading to these 2 versions, everything is fine.

"babel-plugin-module-resolver": "^2.5.0",
"eslint-import-resolver-babel-module": "^3.0.0",

@machineghost
Copy link
Author

That was the problem, thanks so much and sorry for bothering you.

@tleunen
Copy link
Owner

tleunen commented Feb 7, 2017

No worries :) Glad I was able to help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants