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

Parse error with mdx #106

Closed cdfa closed 5 years ago

cdfa commented 5 years ago

Hi, I'm getting a parse error on imports pointing to directories in MDX files. I'm using @rxts/eslint-plugin-mdx to parse the .mdx files. It's possible another package is causing this, but all other imports in my .mdx files work fine and I don't get the error with the default node resolver.

I have his import in FollowReveal.mdx

import { Front, PlaceHolderImage } from "docs/PlayGroundUtils";

File structure:

.
├──  docs
    └── PlayGroundUtils
        ├── Front.jsx
        ├── index.js
        └── PlaceHolderImage.jsx
└── src
    └── FollowReveal
        └── docs
            └── FollowReveal.mdx

where index.js just re-exports the other modules in the directory

Error:

13:41  error  Parse errors in imported module 'docs/PlayGroundUtils': parser.parse is not a function (undefined:undefined)  import/namespace
13:41  error  Parse errors in imported module 'docs/PlayGroundUtils': parser.parse is not a function (undefined:undefined)  import/named
eslintrc.json: ```json { "parser": "babel-eslint", "extends": [ "eslint:recommended", "plugin:react/recommended", "plugin:jest/recommended", "plugin:jest/style", "plugin:eslint-comments/recommended", "plugin:array-func/all", "plugin:import/errors", "plugin:import/warnings", "prettier" ], "env": { "es6": true, "browser": true }, "plugins": ["react", "prettier", "json", "jest", "no-loops", "import"], "parserOptions": { "sourceType": "module" }, "settings": { "react": { "version": "detect" }, "import/resolver": "babel-module", "import/parsers": { "@rxts/eslint-plugin-mdx": [ ".mdx" ] } }, "rules": { ... }, "overrides": [ ..., { "files": ["*.mdx"], "extends": ["plugin:@rxts/mdx/recommended"], "globals": { "React": false }, "rules": { "lines-between-class-members": "off" // See https://github.com/mdx-js/mdx/issues/195 } } ] } ```
.babelrc: ```json { "presets": [ [ "@babel/preset-env", { "modules": false } ], "@babel/preset-react" ], "plugins": [ "@babel/plugin-proposal-class-properties", [ "module-resolver", { "root": ["./"], "extensions": [".js", ".jsx", ".json"] } ] ] } ```
cdfa commented 5 years ago

I just noticed that using the node resolver i do get different errors in a different import, so maybe it's not as babel resolver specific as I thought.

JounQin commented 5 years ago

@rxts/eslint-plugin-mdx only exports a parseForESLint method for now, maybe I can add a parse method for compatibility usage.

cdfa commented 5 years ago

Closing in favour of https://github.com/benmosher/eslint-plugin-import/issues/1433