@babel/node not recognizing ignores from babel.config.js when running babel-node
See original GitHub issueBug Report
Current behavior It’s possible it’s a “feature”, but seems like a bug.
So, I have a babel config that has an ignore function in it. Mostly because where I work we have a couple of internal node modules we publish that have some dist
folders with import
export
statements.
The babel.config.js
looks more or less like this…
module.exports = (api) => {
api.cache(true);
return {
presets: ['@babel/env'],
ignore: [function(filepath) {
if (filepath.includes('my-npm-pkg')) {
return false;
}
return filepath.includes('node_modules');
}]
};
};
When I run the following…
babel-node ./index.js
I get the following error…
However, if I run it with an empty ignore, like this…
babel-node --ignore ' ' ./index.js
Everything works…
Expected behavior
I’d expect that the ignore should be taken from the babel.config.js
even if I don’t have an --ignore
in the command line args.
Environment I’m running on node 12.17.0.
"@babel/core": "^7.10.5",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.10.4"
I also created an example repository here…
https://github.com/jcreamer898/babel-node-ignore
Possible Solution I’m not entirely sure, but maybe it has something to do with https://github.com/babel/babel/blob/main/packages/babel-register/src/node.js#L140?
Does there need to be a check for the babel config’s ignore here? It didn’t seem like that to me because when I console logged the options getting passed here, it didn’t even seem to have the ignore from my babel.config.js
.
https://github.com/babel/babel/blob/main/packages/babel-node/src/_babel-node.js#L94
So, my suspicion is that the --ignore ' '
is just nuking the ignore option totally, and babel.config.js
is firing on a file by file basis later on as they’re processing individual files?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Right, exactly, it’s like it doesn’t work at all when the config file is being used. I think the “default” --ignore is taking over whatever is in the babel config.
I have the same issue, the
only
andignore
options of mybabel.config.json
are ignored when runningbabel-node
. I have to specify the options directly in the clibabel-node --only src,my-library src/index.js