question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using babel runtime, but still got `ReferenceError: Can't find variable: Promise`

See original GitHub issue

I notice that Promise polyfill should be required.

But the question is, I am already using the babel runtime transformer to transform my code, and I got Object.assign() working just fine. Only new Promise() in whatwg fetch library throw error Can't find variable: Promise.

I am currently using require('es6-promise').polyfill();, and it works fine.

I am wondering why I still need promise polyfill since I am using babel runtime?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

1reaction
silvenoncommented, Dec 20, 2016

I’m not sure if this is cool, but this is what I did:

{
  test: /\.jsx?$/,
  include: [
    path.resolve(__dirname, "src"), // our source files
    /whatwg-fetch/, // but also the whatwg-fetch module
  ],
  loader: "babel-loader",
},

This way I’m processing whatwg-fetch with Babel as well, so transform-runtime patches its Promise usage.

0reactions
silvenoncommented, Dec 20, 2016

import isomorphic-fetch works as well because it requires whatwg-fetch, so it will still get processed by webpack with the above config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-transform-runtime
A plugin that enables the re-use of Babel's injected helper code to save on codesize.
Read more >
Babel 7 - ReferenceError: regeneratorRuntime is not defined
Updated Answer: If you are using Babel 7.4.0 or newer, then @babel/polyfill has been deprecated. Instead, you will want to use the following ......
Read more >
referenceerror can t find variable axios - metara.net
Runtime aspect of `HttpStatusCode` missing from JavaScript files. Basically the variable in Javascript can be anything that's valid according to ECMAScript 5.1 ...
Read more >
How to fix regeneratorRuntime is not defined?
Solution · later learned that babel-polyfill is deprecated. So, to solve the regeneratorRuntime problem, do this: · Install regenerator-runtime
Read more >
babel-loader - webpack
You can instead require the Babel runtime as a separate module to avoid the duplication. The following configuration disables automatic per-file runtime ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found