Skip to content

[babel-node] babel-node won't use --config-file when using -e codeToEval #11877

@vvo

Description

@vvo

Bug Report

  • I would like to work on a fix!

Current behavior

Given a configuration file of:

// .test-babelrc.js
module.exports = {
  presets: ["@babel/preset-env"],
};

And a command line of:

yarn babel-node --config-file ./.test-babelrc.js -e "const a = 1"

It will error with: "SyntaxError: /[redacted path]/[eval]: Only var variables are supported in the REPL". Because it's actually not using the configuration file.

The configuration file is not used to eval the code. You can even give the command line a bad configuration file path or mess up the inside syntax of the configuration: it does not matter, it won't be used.

If you rename .test-babelrc.js to .babelrc.js and change command to:

yarn babel-node -e "const a = 1"

Then it works, because somehow now the default babel configuration file location is used.
Also, if you use:

./node_modules/.bin/babel-node --config-file ./.test-babelrc.js ./test.js

Then it works, given a test.js file of:

// test.js
const a = 1;
console.log(a);

PS: I need to use a different default configuration file path (.test-babelrc.js) in the context of my project.

Input Code

I created a repository to reproduce the bug here: https://github.com/vvo/test-babel-node-configuration-file

Expected behavior
The custom configuration file path should be used when combined with the eval code.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = {
  presets: ["@babel/preset-env"],
};

Environment

  System:
    OS: macOS 10.15.5
  Binaries:
    Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm
  npmPackages:
    @babel/core: 7.10.5 => 7.10.5
    @babel/node: 7.10.5 => 7.10.5
    @babel/preset-env: 7.10.4 => 7.10.4
  • Monorepo: n/a
  • How you are using Babel: babel-node

Possible Solution
n/a

Additional context
n/a

Metadata

Metadata

Assignees

Labels

help wantedoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: node

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions