babel: _regeneratorRuntime is not defined when using JSON.stringify (T7041)
Issue originally made by @neverfox
Bug information
- Babel version: 6.4.5
- Node version: 5.3.0
- npm version: 3.5.2
Options
{
"presets": ["es2015", "react", "stage-0"],
"plugins": ["transform-runtime", "add-module-exports", "transform-decorators-legacy"]
}
Input code
import fetch from 'isomorphic-fetch'
function checkStatus (response) {
if (response.status >= 200 && response.status < 300) {
return response
} else {
var error = new Error(response.statusText)
error.response = response
throw error
}
}
function parseJSON (response) {
return response.json()
}
function authorizeApi ({ username, password }) {
return fetch('http://localhost:3001/auth', {
method : 'POST',
headers : {
'Content-Type' : 'application/json'
},
body : JSON.stringify({
type : 'basic',
value : btoa(`${username}:${password}`)
})
})
.then(checkStatus)
.then(parseJSON)
}
export function * authSaga () {
yield authorizeApi({ username: 'username', password: 'password' })
}
Description
I have a working code module using generator functions, but when I add a use of JSON.stringify anywhere in the same file, I start getting the _regeneratorRuntime is not defined
error that you get when generators aren’t recognized. Adding babel-polyfill
makes no difference.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19
Using
require
will not work because function expressions are hoisted. You’ll either need to useimport
or have a separate entry point that loads the polyfill and then this file.I can’t see a reason
JSON.stringify
would affect this, but if feel free to post example output from Babel for both cases so we can compare.