gulp babel, exports is not defined

That is not actually a babel issue, you are just trying to run CommonJS code (transpiled from ES6 export) in the browser without preparation. CommonJS doesn’t run on the browser, you need to use a tool to package it for the browser, such as Webpack or Browserify.

Just by coincidence this week I created a small project on Github that shows a setup of Gulp + ES6 code (using export) + Babel + Webpack: gulp-es6-webpack-example.

In my example you can load JS code on the browser either synchronously (pre-loaded) or asynchronously (lazy-loaded).

Leave a Comment