Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

regeneratorRuntime issue #92

Closed
gabrielstuff opened this issue Dec 13, 2016 · 9 comments
Closed

regeneratorRuntime issue #92

gabrielstuff opened this issue Dec 13, 2016 · 9 comments

Comments

@gabrielstuff
Copy link

gabrielstuff commented Dec 13, 2016

Here is my .babelrc :

{
	"presets": [
		["env", {
			"targets": {
				"chrome": 47,
    		"edge": 13,
    		"firefox": 45,
    		"safari": 10,
    		"node": 6,
    		"ios": 10,
    		"opera": 34
			},
			"modules": "umd"
		}
		]
	]
}

All code *entries() { is tranformed to

entries() {
      var map, opts, name, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, _ref2, _ref3, value, filename;

      return regeneratorRuntime.wrap(function _callee$(_context) {

Which throw a :

VM1014 formdata.min.js:12 Uncaught ReferenceError: regeneratorRuntime is not defined

I then think about adding babel-polyfill or babel-runtime but then what would be the point of that preset 🤔

So here I come, and how should we configure our .babelrc file for regenerators

thanks a lot !

@hzoo
Copy link
Member

hzoo commented Dec 13, 2016

If you are using generators/async and the environment doesn't support it natively we compile using regenerator which uses a runtime. So you'll have to include regeneratorRuntime either yourself or use babel-polyfill. You can also try the https://github.com/babel/babel-preset-env#usebuiltins-boolean

@hzoo
Copy link
Member

hzoo commented Dec 15, 2016

You have to require "regenerator-runtime/runtime" somewhere to get regeneratorRuntime. One way of doing it is via babel-polyfill. This is because your env's don't support generators. You can use the newly added useBuiltIns option like I mentioned ^ too.

@hzoo hzoo closed this as completed Dec 15, 2016
@gabrielstuff
Copy link
Author

@hzoo thanks for the tips.
Unfortunately, I think I'm not using it the right way. What I'd like is to ship a lib which would be usable in : chrome / firefox / IE / Edge
I do not want to require or import anything.

I'm targeting "modules": "umd" and using the lib I generate by including it as a script, see : http://codepen.io/gabrielstuff/pen/RoeZqN

So what I'm trying to obtain is to transpile in the right ENV and make the preset-env plugin include the right element.

When I'm using useBuiltins I get the following code :

if (typeof define === "function" && define.amd) {
    define(['module', 'core-js/modules/es6.typed.data-view', 'core-js/modules/es6.typed.int8-array', 'core-js/modules/es6.typed.uint8-array', 'core-js/modules/es6.typed.int16-array', 'core-js/modules/es6.typed.uint16-array', 'core-js/modules/es6.typed.int32-array', 'core-js/modules/es6.typed.uint32-array', 'core-js/modules/es6.typed.float32-array', 'core-js/modules/es6.typed.float64-array', 'core-js/modules/es6.map', 'core-js/modules/es6.set', 'core-js/modules/es6.weak-map', 'core-js/modules/es6.weak-set', 'core-js/modules/es6.reflect.apply', 'core-js/modules/es6.reflect.construct', 'core-js/modules/es6.reflect.define-property', 'core-js/modules/es6.reflect.delete-property', 'core-js/modules/es6.reflect.get', 'core-js/modules/es6.reflect.get-own-property-descriptor', 'core-js/modules/es6.reflect.get-prototype-of', 'core-js/modules/es6.reflect.has', 'core-js/modules/es6.reflect.is-extensible', 'core-js/modules/es6.reflect.own-keys', 'core-js/modules/es6.reflect.prevent-extensions', 'core-js/modules/es6.reflect.set', 'core-js/modules/es6.reflect.set-prototype-of', 'core-js/modules/es6.promise', 'core-js/modules/es6.symbol', 'core-js/modules/es6.object.is', 'core-js/modules/es6.object.set-prototype-of', 'core-js/modules/es6.function.name', 'core-js/modules/es6.regexp.flags', 'core-js/modules/es6.regexp.match', 'core-js/modules/es6.regexp.replace', 'core-js/modules/es6.regexp.split', 'core-js/modules/es6.regexp.search', 'core-js/modules/es6.array.from', 'core-js/modules/es6.number.is-finite', 'core-js/modules/es6.number.is-nan', 'core-js/modules/es7.array.includes.js', 'core-js/modules/es7.object.values', 'core-js/modules/es7.object.entries', 'core-js/modules/es7.object.get-own-property-descriptors', 'core-js/modules/es7.string.pad-start', 'core-js/modules/es7.string.pad-end', 'core-js/modules/web.timers', 'core-js/modules/web.immediate', 'core-js/modules/web.dom.iterable', 'regenerator-runtime/runtime'], factory);
  } else if (typeof exports !== "undefined") {
    factory(module, require('core-js/modules/es6.typed.data-view'), require('core-js/modules/es6.typed.int8-array'), require('core-js/modules/es6.typed.uint8-array'), require('core-js/modules/es6.typed.int16-array'), require('core-js/modules/es6.typed.uint16-array'), require('core-js/modules/es6.typed.int32-array'), require('core-js/modules/es6.typed.uint32-array'), require('core-js/modules/es6.typed.float32-array'), require('core-js/modules/es6.typed.float64-array'), require('core-js/modules/es6.map'), require('core-js/modules/es6.set'), require('core-js/modules/es6.weak-map'), require('core-js/modules/es6.weak-set'), require('core-js/modules/es6.reflect.apply'), require('core-js/modules/es6.reflect.construct'), require('core-js/modules/es6.reflect.define-property'), require('core-js/modules/es6.reflect.delete-property'), require('core-js/modules/es6.reflect.get'), require('core-js/modules/es6.reflect.get-own-property-descriptor'), require('core-js/modules/es6.reflect.get-prototype-of'), require('core-js/modules/es6.reflect.has'), require('core-js/modules/es6.reflect.is-extensible'), require('core-js/modules/es6.reflect.own-keys'), require('core-js/modules/es6.reflect.prevent-extensions'), require('core-js/modules/es6.reflect.set'), require('core-js/modules/es6.reflect.set-prototype-of'), require('core-js/modules/es6.promise'), require('core-js/modules/es6.symbol'), require('core-js/modules/es6.object.is'), require('core-js/modules/es6.object.set-prototype-of'), require('core-js/modules/es6.function.name'), require('core-js/modules/es6.regexp.flags'), require('core-js/modules/es6.regexp.match'), require('core-js/modules/es6.regexp.replace'), require('core-js/modules/es6.regexp.split'), require('core-js/modules/es6.regexp.search'), require('core-js/modules/es6.array.from'), require('core-js/modules/es6.number.is-finite'), require('core-js/modules/es6.number.is-nan'), require('core-js/modules/es7.array.includes.js'), require('core-js/modules/es7.object.values'), require('core-js/modules/es7.object.entries'), require('core-js/modules/es7.object.get-own-property-descriptors'), require('core-js/modules/es7.string.pad-start'), require('core-js/modules/es7.string.pad-end'), require('core-js/modules/web.timers'), require('core-js/modules/web.immediate'), require('core-js/modules/web.dom.iterable'), require('regenerator-runtime/runtime'));
  } 

Unfortunately this does not help as I'd like to ship a single file. If it was in the case of an app why not, but this is not the case.

Thanks !

@hzoo
Copy link
Member

hzoo commented Jan 3, 2017

Hmm ok - if you are making a library I wouldn't recommend a polyfill then because usually we make it up to the application to decide what polyfills to include not libraries. If you need to use those kinds of things you should check out transform-runtime instead. I haven't been able to modify that to also take in a "useBuiltIns" option yet though.

If you want a single file you'd want to bundle it with something like webpack

@gabrielstuff
Copy link
Author

hmmm.. So I guess I had to wait for transform-runtime to be ready to use in combination with babel-preset.
In the mean time, I should simply use the old way and check my-self for what I need to include ?

Thanks !

@shaunc
Copy link

shaunc commented May 6, 2017

I have node 7.2.1 installed, and configure with

presets: ["es2015", ["env", {
  targets: { "node": true }
}]],

Yet, I am still getting this error. Is there some reason why it is using the polyfill? (Should I open a separate issue? I would think I've just got the wrong config somehow....).

@hzoo
Copy link
Member

hzoo commented May 14, 2017

Yeah @shaunc because you are including es2015 in your preset still? preset-env covers everything so you can remove that.

@shaunc
Copy link

shaunc commented May 14, 2017

@hzoo ... you're absolutely right -- thanks!

@hzoo
Copy link
Member

hzoo commented May 14, 2017

👍 Hopefully with this plugin ordering fix we should be able to error against that automatically in the future (seems to be a common mistake)

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

No branches or pull requests

3 participants