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

cwd: 'babelrc' doesn't find .babelrc.js

Open good-idea opened this issue 7 years ago • 5 comments

I was having trouble getting babel to export aliased modules -- they were always transpiling with absolute paths instead of relative ones. I had been configuring babel with a .babelrc.js file instead of .babelrc --- when I renamed it, things started working as expected.

It would be ideal if .babelrc.js files were supported!

I'm happy to put together a PR for this. It looks like find-babel-config isn't very active, it might make sense to handle this from within this module.

good-idea avatar Aug 17 '18 19:08 good-idea

find-babel-config supports .babelrc.js though: https://github.com/tleunen/find-babel-config/tree/master/test/data/babelrcjs

fatfisz avatar Aug 17 '18 20:08 fatfisz

Yeah... But we'll have to rework that option with Babel 7 anyway I believe... babel.config.js works differently than the other filenames (see https://babeljs.io/docs/en/next/babelconfigjs).

So I wonder how useful is the babelrc custom cwd that we have instead of always using the root project... Defaulting on the root project, except if you provide a custom cwd. No more custom magic values.

tleunen avatar Aug 22 '18 02:08 tleunen

@fatfisz That's odd - I was getting absolute paths (as if it weren't finding the cwd) when I had a .babelrc.js, and it started working with a .babelrc.

@tleunen In the case of a monorepo, with Babel 7's babel.config.js will also be used to help babel identify where package-specific configuration is. I'm not sure of the extent of what the cwd option does --- but the babel.config.js file may not always be the 'correct' working directory.

good-idea avatar Aug 22 '18 02:08 good-idea

What do you mean exactly. If you have one babel.config.js in each "package" in the monorepo. It will be ok. (But then I agree that the project root won't be the same).

But anyway, I think using the new core function loadPartialConfig (as explained here https://github.com/babel/babel/pull/7472) will solve all issues related to that. Since we'll be relying on babel to know what file is used, thus knowing the "root".

tleunen avatar Aug 22 '18 02:08 tleunen

It looks like babel.config.js will be used for setting up global config, and will ignore .babelrc files:

https://babeljs.io/docs/en/next/babelconfigjs

Unless you opt into them using the babelrcs or babelrcRoots options

good-idea avatar Aug 22 '18 16:08 good-idea