2

The entry point for my code starts with the following imports:

import 'source-map-support/register';
import 'babel-polyfill';
console.log('polyfill included?', global._babelPolyfill);

[...]

However, when running I see that global._babelPolyfill is undefined. I also notice that in my transpiled code, there is no require('babel-polyfill').

Why is that?

My guess is that babel thinks that babel-polyfill is not required. However, when I don't include it, I get the following error:

ReferenceError: regeneratorRuntime is not defined
at /opt/node-modules/my-module/node_modules/dependency/promise.js:9:57
at Object.<anonymous> (/opt/node-modules/my-module/node_modules/dependency/promise.js:35:2)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/opt/node-modules/fio/src/file.js:1:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
[...]

So I definitely need it. My guess is that somehow the dependency (another node module I am importing later in my code) is not configured correctly and that when babel transpiles my code it does not detect that, so it still figures babel-polyfill is not required.

I would love actual documentation to back-up actually why that is if that is indeed the case.

UPDATE on why this is not the same as another question: The accepted solution is to use babel-polyfill, but I'm already doing it. My question is why babel-polyfill is not being imported in my transpiled code and therefore not available in my run code.

efeder
  • 552
  • 5
  • 16
  • how are you building the running code? Since you have node_modules, did you also install `babel-polyfill` in your package.json? – Icepickle Dec 20 '17 at 23:04
  • yes, babel-polyfill is a dependency and is installed in the node_modules directory. I am building the code using the babel cli. – efeder Dec 20 '17 at 23:07
  • Possible duplicate of [Babel 6 regeneratorRuntime is not defined](https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined) – Icepickle Dec 20 '17 at 23:11
  • Also note that on the [babel-polyfill page](https://babeljs.io/docs/usage/polyfill/) it mentions that it is quite important to be the first thing called (same goes for the proposed duplicate) – Icepickle Dec 20 '17 at 23:13
  • I tried requiring babel-polyfill first, which didn't fix it. https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined suggests that we import babel-polyfill as the solution, but I am already doing that – efeder Dec 20 '17 at 23:20
  • are you using multiple runtimes or a single runtime chunk, also are you bundling using webpack? – Coty Embry May 22 '20 at 19:15

0 Answers0