eslint-plugin-module-resolver icon indicating copy to clipboard operation
eslint-plugin-module-resolver copied to clipboard

Not compatible with babel.config.js

Open gnuletik opened this issue 5 years ago • 14 comments

Hi, thanks for your plugin !

This module is not compatible with babel.config.js file because find-babel-config does not. See https://github.com/tleunen/find-babel-config/issues/31

Thanks !

gnuletik avatar Dec 07 '18 15:12 gnuletik

@gnuletik Thanks for the feedback. I am going to look at making a PR to that repo. Do you have an example project using babel.config.js

HeroProtagonist avatar Dec 13 '18 03:12 HeroProtagonist

Thanks for your time :)

Here is an example babel.config.js file

module.exports = function () {
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      ['module-resolver', {
        alias: {
          '~components': './src/components',
          '~utils': './src/utils',
        },
        cwd: 'packagejson',
      }],
    ],
  };
};

gnuletik avatar Dec 13 '18 11:12 gnuletik

@gnuletik I have opened a PR to find-babel-config. This should fix the issue.

Until it gets reviewed/merged I am going to do work on config-support branch for this package and reference my fork.

When you have time please let me know if that branch works with your project using the babel.config.js

HeroProtagonist avatar Dec 15 '18 17:12 HeroProtagonist

Thanks !

How can I test locally ? If I install the package from your branch

yarn add --dev 'HeroProtagonist/eslint-plugin-module-resolver#config-support

eslint does not find the plugin

ESLint: 5.9.0.
ESLint couldn't find the plugin "eslint-plugin-module-resolver". This can happen for a couple different reasons:
...

This also occurs when using the master branch

gnuletik avatar Dec 19 '18 21:12 gnuletik

Okay, I succeed to install the plugin from the github branch with

cd node_modules/eslint-plugin-module-resolver/
yarn install
yarn run babel lib --out-dir dist

I tested the plugin, however, find-babel-config throws an error because the api parameter is missing when calling the babel.config.js function. Sorry, I didn't include the api parameter from babel.config.js in my previous comment.

If I disable the cache, babel throws an error and eslint-plugin-import does not work anymore.

babel.config.js

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      ['module-resolver', {
        alias: {
          '~components': './src/components',
          '~utils': './src/utils',
        },
        cwd: 'packagejson',
      }],
    ],
  };
};

.eslintrc.json

{
    "env": {
        "node": true,
        "browser": true,
        "es6": true
    },
    "parser": "babel-eslint",
    "extends": "airbnb",
    "rules": {
        "react/jsx-filename-extension": [1, { "extensions": [".js"] }],
        "module-resolver/use-alias": 2
    },
    "settings": {
        "import/resolver": {
            "babel-module": {}
        }
    },
    "plugins": [
        "module-resolver"
    ]
}

gnuletik avatar Dec 19 '18 23:12 gnuletik

I'm still getting this error with these versions:

eslint-plugin-module-resolver@^0.10.0:
  version "0.10.0"

find-babel-config@^1.1.0, find-babel-config@^1.2.0:
  version "1.2.0"

DEfusion avatar Jun 24 '19 14:06 DEfusion

@DEfusion Hi! Could you share the repository (if public) or config files that represent the problem. Will make it easier to debug. Thanks

HeroProtagonist avatar Jun 26 '19 00:06 HeroProtagonist

for still looking the solution. setting the preset only in production env fix my issue

{
  ...
  env: {
    production: {
      presets: ['react-app'],
    },
  },
}

nucab avatar May 26 '20 17:05 nucab

@gnuletik - I am wondering if the latest version has fixed this and this issue can be closed

HeroProtagonist avatar Jan 04 '21 19:01 HeroProtagonist

@HeroProtagonist Thanks for the feedback ! I'm not using this lib anymore so I cannot test it right now.

gnuletik avatar Jan 05 '21 10:01 gnuletik

I am trying version 1.2.0, but I can't seem to get the linter to warn when using any relative paths. My project is using a babel.config.js file, but it also wouldn't work with a .babelrc.json for what it's worth.

ryanjwessel avatar Jan 15 '21 18:01 ryanjwessel

@HeroProtagonist I am trying version 1.3.0 not worked with babel.config.js

ease-space avatar Jun 06 '21 18:06 ease-space

Was it working in 1.2.0 for you?

HeroProtagonist avatar Jun 07 '21 15:06 HeroProtagonist

@HeroProtagonist No, v1.2.0 not worked

ease-space avatar Jun 20 '21 16:06 ease-space