Skip to content

BabelJS

Created: 2018-06-13 11:53:11 -0700 Modified: 2018-12-07 09:04:23 -0800

Globs don’t use the right working directory / “base” directory

Section titled Globs don’t use the right working directory / “base” directory

I was trying to do something like this:

npx babel src/* src/**/* --out-dir dist

However, it was producing dist/src/foo.js instead of dist/foo.js. There are a couple of solutions:

  1. In this specific case, since I wanted every single file under “src”, I could just have avoided globs altogether and specified “babel src —out-dir dist”.
  2. If globs are needed, then you have to be in the directory that you want as the “base”, so your command would change to this:
cd src && babel ./* ./**/* --out-dir ../dist

The problem is described here. It’s going to be fixed in Babel 7, so if you run into a situation where you can’t use the spread operator, then just stop using the spread operator or upgrade to version 7 (if you can).

This probably just means you’re missing a .babelrc file if you’re trying to use babel-register:

{
// Note: this entire file only exists so that babel-register works
"compact": false,
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}