Search code examples
babeljsmonorepo

Babel: root programmatic options


I seem to not grasp where to put root programmatic options for the babel.

If I have a monorepo and need to tell the different sub packages that they shall look upwards for my babel.config.js then I should put rootMode: "upwards" into the .babelrc of the sub packages, correct? This does not work, because of the resulting error

Error: .rootMode is only allowed in root programmatic options

Somehow I simply can't find any example of where to put/use root programmatic options... Can anyone point me in the right direction?


Solution

  • If you are using Webpack, you need to put it there.

    module: {
      [..]
      rules: [
        // Transpile ES6 Javascript into ES5 with babel loader
        {
          test: /\.jsx?$/,
          exclude: [/node_modules/, /json/],
          loader: 'babel-loader',
          options: {
            rootMode: 'upward'
          },
        },
        [..]
      ],
      [..]
    },
    

    Otherwise I had the same issue than you, I can't put it in the package.json file using the key babel.