babel / babel-brunch

Brunch plugin for Babel
ISC License
69 stars 38 forks source link

trying to use transform-async-to-generator #40

Closed jmls closed 7 years ago

jmls commented 7 years ago

I want to use the babel plugin http://babeljs.io/docs/plugins/transform-async-to-generator , in order to compile this code:

async function getSessionData() {
    [snip]
}

so I npm installed babel-runtime, and the appropriate babel plugins (and brunch plugins).

Everything compiles just peachy ;)

However, (there's always an however) - when it comes to running the app, I now get an error

Uncaught reference error: require is not defined

and, indeed, looking at the generated application.js code, I see this

var _keys = require("babel-runtime/core-js/object/keys");
var _freeze = require("babel-runtime/core-js/object/freeze");

I am running with module wrapping false

    modules: {
        definition: false,
        wrapper: false
    },

Before I installed babel, everything was fine and dandy, and working well, so I suspect that babel has some requirements (see what I did there?) that conflict with the modules setting

What do I need to change in order to use babel ?

paulmillr commented 7 years ago

I don't see why babel runtime is needed here. Try it without the runtine.

jmls commented 7 years ago

ok, so I removed babel-runtime, and have this in the config:


        babel: {
            plugins: ['transform-async-to-generator']
        }

everything compiles (good)

but I error in the browser (bad)

Uncaught ReferenceError: regeneratorRuntime is not defined

which is why I thought I needed the runtime in the first place ;)

goshacmd commented 7 years ago

Generators need the regeneratorRuntime polyfill which comes from the babel-polyfill module. You do need the modules and npm integration for that to work.

jmls commented 7 years ago

oh, blast. Thanks.

jmls commented 7 years ago

not that I'm against moving to npm and modules, but I'm somewhat stuck with how I convert my existing js files (see example below) over to a module format (I have several dozen .js files (1 for each controller / factory / service etc)

/* global angular */
(() => {
    'use strict';
    /** @ngInject */
    function sdkFactory($http) {
        return {};
    }

    angular
        .module('myApp')
        .factory('sdkFactory', sdkFactory);
})();
jmls commented 7 years ago

Closing, as not relevant anymore (I'm working out how to use ES6 modules).

thanks for the help.