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

Still getting import/no-extraneous-dependencies error #77

Open
itrelease opened this issue Nov 25, 2017 · 15 comments
Open

Still getting import/no-extraneous-dependencies error #77

itrelease opened this issue Nov 25, 2017 · 15 comments
Assignees

Comments

@itrelease
Copy link

itrelease commented Nov 25, 2017

In my .babelrc:

{
  "presets": ["env", "react"],
  "plugins": [
    "react-hot-loader/babel",
    "transform-class-properties",
    "transform-object-rest-spread",
    [
      "module-resolver",
      {
        "alias": {
          "@root": "./src/scripts/",
          "@components": "./src/scripts/components",
          "@reducers": "./src/scripts/reducers",
          "@utils": "./src/scripts/utils"
        }
      }
    ]
  ],
  "retainLines": true
}

in .eslintrc:

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

but eslint getting error ([eslint] '@components/Block' should be listed in the project's dependencies. Run 'npm i -S @components/Block' to add it (import/no-extraneous-dependencies)) on line:

import { DraggableBlock } from '@components/Block';
@QuentinBrosse
Copy link

QuentinBrosse commented Nov 28, 2017

I had the same issue but downgrading to these versions did the job for me:

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

@chuck0523
Copy link

chuck0523 commented Dec 8, 2017

Below worked fine for me.

"settings": {
    "import/resolver": {
      "babel-module": {
        "root": ["./src"],
        "alias": { "config": "./config" }
      },
    }
  },

Found example in code: https://github.com/tleunen/eslint-import-resolver-babel-module/blob/master/src/index.js#L87

@ndillon1
Copy link

ndillon1 commented Jan 8, 2018

@tleunen are you able to address this issue ? I am also having the same problem and the above workarounds do not solve the problem

babel.rc

{
  "presets": ["react-native"],
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "@components": "./app/components",
          "@routes": "./app/routes",
          "@util": "./app/util",
        }
      }
    ]
  ]
}

eslint.js

settings: {
    'import/resolver': {
      node: {
        extensions: ['.js', '.android.js', '.ios.js'],
      },
      'babel-module': {},
    },
    node: true,
  },

@lucasbento
Copy link

@tleunen: can you shed some light on this? I thought the plugin wasn't loading the options but it is,
not sure what's wrong but I'm getting the same error and everything seems to be configured right:

// .babelrc
{
  "presets": ["react-native"],
  "plugins": [
    [
      "module-resolver",
      {
        "cwd": "babelrc",
        "alias": {
          "@app": "./app",
          "@common": "./app/common",
          "@config": "./app/config",
        }
      }
    ]
  ]
}
// .eslintrc
{
  "parser": "babel-eslint",
  "plugins": [
    "react-native"
  ],
  "env": {
    "jest": true
  },
  "extends": [
    "airbnb",
    "plugin:react-native/all"
  ],
  "settings": {
    "import/resolver": {
      "react-native": {},
      "babel-module": {}
    }
  },
  "rules": {
    "import/no-extraneous-dependencies": ["error", {"devDependencies": ["__tests__/**/*.js", "__mocks__/**/*.js" , "storybook/**/*.js"]}],
  }
}
// package.json
"babel-plugin-module-resolver": "^3.0.0",
"eslint-import-resolver-babel-module": "^4.0.0",

@itrelease
Copy link
Author

@lucasbento it seems the problem with @ symbol, so as a workaround you can prefix your stuff with src- or something else like:

"alias": {
  "src-app": "./app",
  "src-common": "./app/common",
  "src-config": "./app/config",
}

@lucasbento
Copy link

lucasbento commented Jan 9, 2018

@itrelease: thanks, that's exactly it!

The problem is that I still want to use @, src- doesn't look very intuitive for me, do you know if there's an specific reason for it to not work?

Edit: I removed any prefix and kept only app/common/config, it works fine that way, good enough, thanks, @itrelease!

olegdeezus added a commit to olegdeezus/ChronoMint-RN that referenced this issue Feb 9, 2018
Remove @ prefix from chronobank aliases,
because of eslint-import-resolver-babel-module problem:
tleunen/eslint-import-resolver-babel-module#77

May be reverted in the future
@Tomekmularczyk
Copy link

I had the same problem with @ prefix. Sad it doesn't work.

@tayfunyasar
Copy link

I'm facing same issue and I want to use "@"

@Nopzen
Copy link

Nopzen commented Jun 14, 2018

can confirm also issues with "@" sign

Edit:
Sorry for lack of information.

Iam on:
babel-plugin-module-resolver: ^5.0.0-beta.0
babel version: ^7.0.0-beta.51

@laugri
Copy link

laugri commented Jul 17, 2018

Any news on this ? Running into the same problem.

@ItsNoHax
Copy link

How is this still not fixed :( I really want to use "@" to specify that the import is an alias and I'd rather not turn the rule off as it's a valid rule for every other use case.

@tleunen
Copy link
Owner

tleunen commented Aug 23, 2018

@ItsNoHax - Well. I believe we are all developers here. So if something bothers you because it's buggy, other devs will thank you if you actually try to fix it.

Having said that, I'll do my best to take a look at it by end of next week.

@tleunen tleunen self-assigned this Aug 23, 2018
@ItsNoHax
Copy link

Hey @tleunen, sorry if I came off rude.

Thanks for taking your time to look into it and if you need me to help you verify your solution is correct, just let me know.

@artemjackson
Copy link

artemjackson commented Sep 3, 2018

As workaround you may add "import/core-modules": "@your-package-name" to .eslintrc settings section

@ashton
Copy link

ashton commented Jan 30, 2019

I bumped with this issue today and I analysed the code and the problem is at the eslint-plugin-import, more specifically, here.

Our aliases matches with this regex, and this causes the plugin to recognise the import as an external scoped dependency (because it is the same format), so it tries to find it in node_modules and because it's not there it throws the error.

In the open issue the author implicitly says (as far as my interpretation goes) that we shouldn't name our aliases as the same as valid npm packages (or namespaces).

I don't know exactly to fix this without messing with the actual scoped external dependencies, because I didn't look to the rest of the code to see how it works as a whole, but I hope that this info someway helps.

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