-
Notifications
You must be signed in to change notification settings - Fork 31
Support babel.config.js #89
Comments
Thanks for asking. I'll add it when time allows it :) |
@tleunen Thanks for your response! I'll look forward to it. Please let me know when you need any reviewer. |
Hi, I'm attempting to migrate over to babel 7, and am using a |
I'm having the same issue after migrating to babel.config.js (changing nothing else), even with .eslintrc (unchanged) {
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"settings": {
"import/resolver": {
"babel-module": {}
}
} babel.config.js (converted from .babelrc) module.exports = {
presets: [
'@babel/preset-env',
],
plugins: [
[
'module-resolver',
{
root: [
'./app'
],
transformFunctions: [
'require',
'require.context',
'require.resolve',
'import'
]
}
],
],
// ...
} |
Update: Running cd src
eslint file-to-lint.js
../src/file-to-lint.js
12:19 error Unable to resolve path to module '...' import/no-unresolved I got the above to work as well by copying the |
I think what is needed is for the #101 properly sets the current working directory for the initialization of Babel's option manager so that it performs discovery from the correct place. However, with Since |
Any update on this? I need this too :( |
As far as I can tell from reading code, it seems as though this should already work if you specify a Doing anything like I said in my previous comment is probably unsafe, because it could cause a |
I am mistaken. I had dug into this before and come to an earlier conclusion. I returned to try to make a PR and reached a different conclusion. I'm searching for a solution that doesn't involve I think a solution may be to treat the ESLint root as the project root rather than the root found by |
I've been able to solve this with a local workaround in my own project. Here are the relevant parts of my const babel = require('@babel/core');
const babelOptions = babel.loadOptions({ cwd: __dirname });
const babelModuleResolver = babelOptions.plugins.find(
({ key }) => key === 'module-resolver',
);
// ...
'import/resolver': {
'babel-module': babelModuleResolver.options,
}
// ... With this setup, |
Any idea why it falls to resolve in your project? Cause it would be great to fix this once and for all 🙂 |
I think the root cause is the In my project, the nearest Babel will, by default, check a given root directory for The However, some users or IDEs may run ESLint from somewhere other than the root of the project. For example, my understanding is that this is why options like Unfortunately, the Taking all this into consideration, these are some options to consider:
It would be a breaking change, but I like this last option the best. I believe a Babel configuration file is the best place to configure On a related issue, I'm not sure what the use cases are for the |
Taking the minimal approach to option 4 here tleunen#89 (comment)
I would lie saying that I remember, but I believe you're right indeed. Running eslint in an IDE usually runs it from the file you run the linting process. Ideally, I would like having this eslint plugin to be as simple as possible, without having a need to provide any options since most of it could be taken from the options of the babel plugin I believe. |
I had some good success reconfiguring a project to use only babelOptions to supply rootMode upwards and everything else configured in babel.config.js. Configuring just root to be __dirname from eslint config would also probably work. If you want help, I could lend a hand with packing the changes and we could try a major version that removes everything and makes all the options just babel options. |
Yes please @tilgovi :) Thank you so much for investigating and finding a solution |
As of Babel 7, it's recommended to use
babel.config.js
. Any plan to support it?The text was updated successfully, but these errors were encountered: