0

I cannot make rollup transform my ES6 code into ES5. It stays trowing a message Warning: Error transforming main.js with 'babel' plugin: It looks like your Babel configuration specifies a module transformer. Please disable it. If you're using the "es2015" preset, consider using "es2015-rollup" instead. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information Use --force to continue.

My .babelrc

{
  "presets": [
    [
      "es2015-rollup",
      {
        "modules": false
      }
    ]
  ],
  "plugins": ["external-helpers"]
}

My .gruntfile

"use strict";
var babel = require('rollup-plugin-babel');

module.exports = function( grunt ) {

  grunt.initConfig({

    //...

    rollup: {
      options: {
        plugins: function () {
          return [
            babel({
              babelrc: false,
              presets: ["es2015-rollup"]
            })
          ];
        },
      },
      main: {
        'dest': 'build/js/bundle.js',
        'src' : 'src/js/main.js',
      },
    },

  //...

  });

  // Load the tasks
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-notify');
  grunt.loadNpmTasks('grunt-postcss');
  grunt.loadNpmTasks('grunt-rollup');

  grunt.registerTask( 'default', [ 'rollup', 'watch' ] );
  //...
};

My devDependencies

  "devDependencies": {
    "autoprefixer": "^6.2.3",
    "babel-plugin-external-helpers": "^6.8.0",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-es2015-rollup": "^1.2.0",
    "grunt": "^0.4.5",
    "grunt-babel": "^6.0.0",
    "grunt-contrib-sass": "^0.9.2",
    "grunt-contrib-uglify": "^0.11.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-notify": "^0.4.3",
    "grunt-postcss": "^0.7.1",
    "grunt-rollup": "^0.8.0",
    "rollup-plugin-babel": "^2.6.1"
  }

As you can see, I use the es2015-rollup preset and not es2015 as the warning suggests. Another thing is that if I remove the presets, my code doesn't get transpilled at all.

Filipe Merker
  • 2,428
  • 1
  • 25
  • 41

2 Answers2

0

plugins option should be an array, not a function.

Also, in .babelrc, you should use es2015 instead of es2015-rollup, because the rollup version is just es2015 with external-helpers plugin.

0

If you set babelrc: false, your configuration will not read .babelrc configuration file.

ignore your .babelrc file and try this in your babel plugin configuration in Gruntfile.js:

 babel({
    babelrc: false,
    presets: [["es2015",{modules:false}]],
    exclude: ['./node_modules/**/*'], //make sure to point to your folder path
    plugins: ["external-helpers"]
 })
Pedro Tainha
  • 497
  • 2
  • 6
  • 14