babel / babel-loader

📦 Babel loader for webpack
MIT License
4.83k stars 451 forks source link

Uncaught ReferenceError: regeneratorRuntime is not defined #484

Closed axe-z closed 7 years ago

axe-z commented 7 years ago

I want to use webpack for my presets, no babelrc, there are so many preset's everywhere on the web, it's hard to know which way to go, I' ve tired everything...

 {
           test: /\.js$/,
           exclude: /(node_modules|bower_components)/,
           use: {
             loader: 'babel-loader',
             options: {
                presets: ["es2015",'stage-0', "es2015-native-modules-and-generators", 'stage-1', 'stage-2', 'stage-3', 'react']
         }
     }
},

I just want a loader preset that can run GENERATORS. Any idea ?

krizzu commented 7 years ago

Hey @axe-z Have a look at this babel plugin. and make sure that you prove babel-polyfill in your project

hzoo commented 7 years ago

You can't combine both es2015-native-modules-and-generators and es2015 because it will run the regenerator transform.

Babel preset for all es2015 plugins MINUS TWO:

babel-plugin-transform-es2015-modules-commonjs babel-plugin-transform-regenerator

I would remove both and use https://github.com/babel/babel-preset-env. You don't need stage-0,1,2,3. Stage 0 includes 1, which includes 2, etc.

{
  "presets": [
    ["env", {
      "targets": { node: "6" }, // specify targets here
    }]
    "stage-0",
    "react"
  ]
}
axe-z commented 7 years ago

I'm asking if it's possible, to add a preset, IN WEBPACK, that would handle generators. I do know that the list i've got there is to much, but still this will not run generators.

cjohnweb commented 7 years ago

babel-polyfill

Here is a webpack.config.js file I use:

const path = require('path');

module.exports = { entry: ['babel-polyfill', path.join(__dirname,'heartbeat.jsx')], output: {filename: './pages/heartbeat/assets/heartbeat-bundle.js'}, module:{ rules: [{ test: [/.jsx?$/, /.js?$/], exclude: /(node_modules)/, use: [{ loader: 'babel-loader', options: { presets: ['es2015','react'] } }] }] }, devtool: 'source-map', resolve: { extensions: [".js",".jsx"] } };

axe-z commented 7 years ago

tks , i'll try that, this really runs GENERATORS ? if so tks alot.

axe-z commented 7 years ago

In any case, this should really realy , I mean really be simpler. with presets like : latest ...

tiendq commented 6 years ago

Use babel-plugin-transform-runtime to fix this issue.

ziszo commented 5 years ago

babel-polyfill works for me in my vue-test-utils unit test with mocha.

xeptore commented 5 years ago

I had the same problem using webpack with babel 7. i imported regenerator-runtime/runtime in main app entry file and works fine.

chiamtc commented 5 years ago

I did import '@babel/polyfill' and fixed it in babel7

jeremytenjo commented 4 years ago

Fixed by adding

import 'core-js/stable'; import 'regenerator-runtime/runtime';