2

I want to transpile the contents of my src directory as well as some packages in node_modules with the help of babel . I'm using the following command as my npm script in package.json:

"build": "babel ./packages/myproject/src --include packages/myproject/node_modules/abc-,packages/leaf-sitemap/node_modules/qwe- --out-dir ./packages/myproject/dist"

in order to include all packages which start with abc- or qwe-

The output error I get is:

Successfully compiled 14 files with Babel.
/Users/me/code/packages/abc-schemas/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose'

Babel compiles the contents of my src folder successfully however it doesn't transpile the contents of node_module packages which start with abc- or qwe-.

What I tried:

  1. using regex after the include statement.
  2. adding include in babel.config.js at root level like so:

    include: [ /node_modules/(abc-|qwe-)/ ]

The babel packages I'm using: "@babel/cli": "^7.5.5", "@babel/core": "^7.5.5"

but all plugin proposals are of version 7.0.0.

Not sure if this is relevant but the packages which start with abc- or qwe- are symlinks. Not sure if this complicates my problem.

None of these attempts didn't help. What am I doing wrong?

UPDATE: I tried a few more attempts with globbing as per @Powell Ye comment. I restricted myself to just abc- type packages. It seems that - is a special character in globbing patterns so removing it made progress:

"build": "babel ./packages/myproject/src --include packages/myproject/node_modules/abc* --out-dir ./packages/myproject/dist"

However I still got Octal literal in strict mode BABEL_PARSE_ERROR parsing error.

hitchhiker
  • 1,099
  • 5
  • 19
  • 44
  • Have you tried using glob patterns? Which babel version is in question? – Pa Ye Dec 02 '19 at 13:41
  • @PowellYe I tried `--include +(packages/myproject/node_modules/abc-*|packages/myproject/node_modules/qwe-*)` but this returned the error `sh: -c: line 0: syntax error near unexpected token `('` I'm not sure if the globbing pattern is not correct or babel doesn't know to parse it – hitchhiker Dec 02 '19 at 13:51
  • `--include`` doesn't seem to be a valid option in Babel CLI v7. Have you tried `--only`? – Pa Ye Dec 04 '19 at 10:37

0 Answers0