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

Possible regression with v5.1.0 #102

Open
diegohaz opened this issue Apr 26, 2019 · 9 comments · May be fixed by #104
Open

Possible regression with v5.1.0 #102

diegohaz opened this issue Apr 26, 2019 · 9 comments · May be fixed by #104

Comments

@diegohaz
Copy link

diegohaz commented Apr 26, 2019

Hey, thank you very much for this project.

I've upgraded eslint-import-resolver-babel-module in my project from v5.0.1 to v5.1.0 and started seeing errors on yarn lint.

Here's a reproduction (tested, can just copypaste and execute):

git clone https://github.com/reakit/reakit
cd reakit
git checkout 1ec0a3a1f3e53f4fa0665e1a67e50cbd90c1bf17
yarn
yarn lint # no errors with v5.0.1
yarn upgrade [email protected]
yarn lint # a bunch of errors

One of the revelant errors:

[eslint-import-resolver-babel-module] Error: [BABEL] /Users/diegohaz/Projects/test/reakit/packages/website/src/templates/Docs.tsx: `babel-preset-gatsby` has been loaded, which consumes config generated by the Gatsby CLI. Set `NODE_ENV=test` to bypass, or run `gatsby build` first. (While processing: "/Users/diegohaz/Projects/test/reakit/node_modules/babel-preset-gatsby/index.js")
    at loadCachedConfig (/Users/diegohaz/Projects/test/reakit/node_modules/babel-preset-gatsby/index.js:16:15)
    at preset (/Users/diegohaz/Projects/test/reakit/node_modules/babel-preset-gatsby/index.js:29:29)
    at loadDescriptor (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/full.js:165:14)
    at cachedFunction (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/caching.js:33:19)
    at loadPresetDescriptor (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/full.js:235:63)
    at config.presets.reduce (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/full.js:77:21)
    at Array.reduce (<anonymous>)
    at recurseDescriptors (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/full.js:74:38)
    at loadFullConfig (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/full.js:108:6)
    at loadOptions (/Users/diegohaz/Projects/test/reakit/node_modules/@babel/core/lib/config/index.js:27:36)
See: https://github.com/tleunen/eslint-import-resolver-babel-module/pull/34

If I run it like NODE_ENV=test yarn lint, it passes without errors, but I've never needed to do so. I'm not sure if it's the right solution.

For now, I'm gonna stick with v5.0.1

@williansabiao
Copy link

It breaks my alias paths as well. I put back the v5.0.1, and it worked again.

@tleunen
Copy link
Owner

tleunen commented May 1, 2019

@williansabiao Could you share your config/alias?

@buz-zard mind taking a look?

@karolis-sh
Copy link
Contributor

@diegohaz regards babel-preset-gatsby the v5.0.1 version loads babel config from root and root config doesn't have babel-preset-gatsby plugin enabled. That's why the tests passed.

From v.5.1.0 babel configs are resolved from the package the code is analysed, so for packages/website package the babel config is taken from packages/website/babel.config.js. As the error is self explanatory this seems as expected behaviour for me.

@williansabiao need the config to understand what might be the issue.

@williansabiao
Copy link

williansabiao commented May 29, 2019

Sorry for my delay guys.

{
  "extends": ["airbnb", "plugin:cypress/recommended", "plugin:jest/recommended"],
  "parser": "babel-eslint",
  "plugins": [
    "cypress",
    "react-hooks"
  ],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
        "jsx": true,
        "impliedStrict": false
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "cypress/globals": true
  },
  "settings": {
    "react": {
      "pragma": "React",
      "version": "16.8.6"
    },
    "import/resolver": {
      "babel-module": {
        "pwd": "./",
        "~": "./src",
        "API": "./src/utils/axios-api.js",
        "Common": "./src/components/Common",
      }
    }
  },
  "rules": {
    "jsx-a11y/anchor-is-valid": [ "error", {
      "components": [ "Link" ],
      "specialLink": [ "hrefLeft", "hrefRight", "to" ],
      "aspects": [ "noHref", "invalidHref", "preferButton" ]
    }],
    "indent": ["error", 2],
    "id-length": 0,
    "react/jsx-indent": [2, 2],
    "react/jsx-indent-props": [2, 2],
    "semi": ["error", "never"],
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "import/no-extraneous-dependencies": ["error", {"packageDir": "./"}],
    "react/jsx-one-expression-per-line": 0,
    "linebreak-style": 0,
    "jsx-a11y/label-has-for": [ 2, {
      "components": [ "Label" ],
      "required": {
          "some": [ "nesting", "id" ]
      },
      "allowChildren": false
    }],
    "jsx-a11y/media-has-caption": 0,
    "import/no-webpack-loader-syntax": 0,
    "allowSyntheticDefaultImports": true
  }
}

@buz-zard @tleunen

@karolis-sh
Copy link
Contributor

@williansabiao and where this eslint config file is located? A repro project structure would help.

@williansabiao
Copy link

williansabiao commented May 30, 2019

This file is located in the root path. I'll try to create a repro project structure to send here late.

I have the same babel.config.js file working for 5.0.1 version.

@williansabiao
Copy link

The repo is here: https://github.com/williansabiao/test-eslint-import-resolver-babel-module

I believe it happens because of the package.json inside each component folder. Once a package.json is there, the eslint is trying to use the alias from this package.json. However, my package.json it's just to name and declare which file should be used on the module import. It was working fine on the v5.0.1.

@buz-zard

@karolis-sh karolis-sh linked a pull request Jun 6, 2019 that will close this issue
@karolis-sh
Copy link
Contributor

karolis-sh commented Jun 6, 2019

@amilajack ok I think got a fix in #104

@williansabiao
Copy link

@buz-zard I tested here with your fix, and it looks great. It's working with your fixes here. Waiting the next versio o/ Thanks.

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

Successfully merging a pull request may close this issue.

4 participants