0

am using the command

npx babel-node --ignore=' ' --extensions='.ts,.tsx,.js,.jsx,.es6,.es' test.js

to compile the script named test.js .

test.js imports import template from 'lodash-es/template'; and I would like it to be compiled too.

Adding ignore or include or exclude options regex at babel.config.js doesn't work. How do i add an inline --ignore option ({ ignore: [/node_modules\/(?!lodash-es)/] }) like babel.config.js? Why does { ignore: [/node_modules\/(?!lodash-es)/] } work with @babel/register and not with babel.config.js ?

Below is test.js:

import fs from 'fs';
import template from 'lodash-es/template';
console.log(template);

export default function () {

};

package.json:

"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@babel/node": "^7.8.4",

Problem seems to be similar to https://github.com/facebook/jest/issues/6229

McKabue
  • 2,076
  • 1
  • 19
  • 34

1 Answers1

3

I resolved the issue with: --ignore="/node_modules\/(?\!lodash-es)/"

npx babel-node --config-file="./babel.config.js" --ignore="/node_modules\/(?\!lodash-es)/" --extensions='.ts,.tsx,.js,.jsx,.es6,.es' test.js

using --ignore=' ' will also work, but you may start getting

[BABEL] Note: The code generator has deoptimised the styling of {filename} as it exceeds the max of 500KB.

because Babel will compile all imported node_modues, which is quite expensive.

McKabue
  • 2,076
  • 1
  • 19
  • 34
  • The argument works well. Is it possible to hide --ignore argument into a settings file babel.config.js. I tried to do it. But it didn't affect. – Victor Shelepen Jul 23 '21 at 12:39