question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@babel/node not recognizing ignores from babel.config.js when running babel-node

See original GitHub issue

Bug 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jcreamer898commented, Jul 31, 2020

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.

1reaction
Edmond-XavierCollotcommented, Sep 6, 2020

I have the same issue, the only and ignore options of my babel.config.json are ignored when running babel-node. I have to specify the options directly in the cli babel-node --only src,my-library src/index.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Babel-node ignores or misbehaves when I add ...
I resolved the issue with: --ignore="/node_modules\/(?\!lodash-es)/". npx babel-node --config-file="./babel.config.js" ...
Read more >
babel/node
babel -node is a CLI that works exactly the same as the Node.js CLI, with the added benefit of compiling with Babel presets...
Read more >
Configure Babel
Create a file called babel.config.json with the following content at the root of your ... You are allowed to access any Node.js APIs,...
Read more >
Options · Babel
If passing options via @babel/cli you'll need to kebab-case the names. i.e. npx babel --root-mode upward file.js # equivalent of passing the rootMode...
Read more >
Config Files · Babel
babelrc file, with no extension. package.json files, with a "babel" key. Project-wide configuration.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found