Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jmls opened this issue Aug 22, 2016 · 6 comments
Closed

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

jmls opened this issue Aug 22, 2016 · 6 comments

Comments

@jmls
Copy link

jmls commented Aug 22, 2016

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
Copy link
Contributor

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

@jmls
Copy link
Author

jmls commented Aug 22, 2016

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
Copy link
Contributor

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
Copy link
Author

jmls commented Aug 22, 2016

oh, blast. Thanks.

@jmls
Copy link
Author

jmls commented Aug 22, 2016

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
Copy link
Author

jmls commented Aug 26, 2016

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

thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants