ReferenceError regeneratorRuntime is not defined
See original GitHub issueI’m building an SSR template, and when I use @babebl/register and then execute webpack (config), the system reported an error. I tried @babel/polyfill and @babel/plugin-transform-runtime, but none of them worked.
Input code
index.js:
require("ignore-styles");
require("@babel/register")({
ignore: [/\/(build|node_modules)\//],
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["@babel/plugin-syntax-dynamic-import", "dynamic-import-node"]
});
require("./server");
server.js
const config = require('../config/webpack.dev.config.js')
const webpack = require('webpack')
const express = require('express')
const webpackDevMiddleware = require('webpack-dev-middleware')
const reactRouter = require('react-router')
const StaticRouter = reactRouter.reactRouter;
const app = express()
const complier = webpack(config)
const PORT = 8090
...
app.use(webpackDevMiddleware(complier, {
publicPath: config.output.publicPath
}))
app.listen(PORT , function() {
console.log(`SSR running on port ${PORT }`);
})
webpack.dev.config.js
const paths = require('./paths')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: ['webpack-hot-middleware/client?reload=true', paths.appIndexJs],
output: {
path: paths.clientBuild,
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: paths.publicPath
},
devtool: 'eval-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: "2",
targets: {
browsers: ['last 2 versions', 'ie >= 9'],
},
}],
'@babel/preset-react'
]
}
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new htmlWebpackPlugin({
template: './client/index.html',
filename: 'index.html'
})
]
}
Error message
Environment
- Babel version(s): 7.4.3
- Node/npm version: [e.g. Node 10.15.3/npm 6.4.1]
- OS: window 10
Rep
https://github.com/xuchenchenBoy/ssr (Please execute npm run dev:server and release notes in server.js)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:22
- Comments:68 (5 by maintainers)
Top Results From Across the Web
How to fix regeneratorRuntime is not defined?
I have ran into a problem, the error is regeneratorRuntime is not defined while working with React and Parcel bundler.
Read more >Babel 6 regeneratorRuntime is not defined - Stack Overflow
This only works because it no longer transforms async/await and thus no longer needs the regeneratorRuntime and because it's not transformed it will...
Read more >Parcel, how to fix the `regeneratorRuntime is not defined` error
I run into this problem in a project using Babel as soon as I added an async function, but the problem is the...
Read more >regeneratorRuntime is not defined when running jest test
I got the ReferenceError: regeneratorRuntime is not defined error. Please attach your logs beforehand. ○ Test suite failed to run ReferenceError: ...
Read more >Blank Admin Page: regeneratorRuntime is not defined (babel?)
Uncaught ReferenceError: regeneratorRuntime is not defined ... Still experiencing the issue while deploying with Heroku, no idea how to fix ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
I had this issue using rollup with babel. I just used this babel config to resolve it :
You have used at least one of these features and it’s not supported in at least one of your
target
s (['last 2 versions', 'ie >= 9']
):async
;function*
); and/orasync
generatorsAs a result,
@babel/preset-env
decides to use@babel/plugin-transform-regenerator
, which relies onregeneratorRuntime
being available globally.To fix this, simply use
regenerator-runtime
, following the instructions in its README to ensureregeneratorRuntime
is made available globally.