Closed karolis-sh closed 5 years ago
Hmm.. I wonder if this is because the eslint config is not in the same directory as the babel config.
You could try to play with the cwd
option. I believe that having cwd: 'babelrc'
, might fix it for you.
I tried both "cwd": "babelrc",
and "cwd": "packagejson",
- no success.
Also tried to make the root .eslintrc.json
file as "root": true,
and move the import/resolver
part to /packages/my-lib/.eslintrc.json
with the same result.
root: true
is used by eslint only, not really by the plugin.
Is the babel plugin working fine for you? Only eslint has issues?
I'd try to see the output of these lines in your case. Maybe you can find what needs to be fixed. I never tried to setup the plugin in a monorepo, so it might as well be a valid issue ;)
Yes, the babel plugin itself runs as expected - resolves the aliases and transpiles the code. Only the ESlint has this issue.
Ok, I'll try to look into this later.
It affects my monorepo setup, i now get warnings every time i run eslint. Is there any chance to resolve this anytime soon?
I still get the eslint error despite the fix commit. Can you provide a more specific example so that I can follow?
What I did is that I add :
./projects/ui/.babelrc
"plugins": [
["module-resolver", {
"cwd": ".babelrc", // either babelrc or packagejson did not work
"alias": {
"~": "./src"
}
}],]
./.eslintrc
"settings": {
"import/resolver": {
"babel-module": {
"alias": {
"~": "./src"
}
},
"node": {
"moduleDirectory": ["node_modules", "src"],
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
and I still get
import _var from '~/styles/variableStyles';
Unable to resolve path to module '~/styles/variableStyles'.eslint(import/no-unresolved)
The babel-module-resolver work well but this lint error is like an annoying itch
The minimal setup would be something like this:
./projects/ui/.babelrc
:
{
"plugins": [
["module-resolver", {
"alias": {
"~": "./src"
}
}]
]
}
./.eslintrc
:
{
"parser": "babel-eslint",
"settings": {
"import/resolver": {
"babel-module": {}
}
}
}
(the parser
might be optional, I don't have a bare-bones example at the moment)
After updating to babel 7 in our monorepo project, I noticed that running ESlint from root directory the aliases fail. Thought running ESlint from the
./packages/my-lib
it validates as expected.(The code runs and transpiles via babel fine)
Dependencies:
Also
yarn - 1.13.0
and"lerna": "^3.10.6",
<project-root>/.eslintrc.json
:<project-root>/packages/my-lib/.babelrc
:The error:
Unable to resolve path to module '~/app/constants' import/no-unresolved
I'd be happy to submit a MR if someone would provide a hint :)