Реакция: ReferenceError: регенераторRuntime не определен - PullRequest
0 голосов
/ 26 ноября 2018

Я пытаюсь использовать async и await в своем приложении реакции.

   onSubmit = async (model) => {
        await this.setState({ data: model });
    }

После добавления приведенного выше кода я получаю сообщение об ошибке в консоли браузера.

ReferenceError:регенераторRuntime не определено

.babelrc

{
    "presets": ["@babel/preset-env", "@babel/preset-react"],
    "plugins": [
        "@babel/plugin-proposal-class-properties"
    ],
    "sourceMaps": "inline"

}

webpack.config.js

const path = require("path");
const WebpackShellPlugin = require("webpack-shell-plugin");
const nodeExternals = require("webpack-node-externals");
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = [
    {
    Server config removed

 },

    {
        entry: {
            app1: './src/public/app1/index.js',
            app2: './src/public/app2/index.js',
            app3: './src/public/app3/index.js',
        },
        devtool: "source-map",
        output: {
            path: __dirname + '/dist/public/',
            publicPath: '/',
            filename: '[name]/bundle.js',
            devtoolLineToLine: true,
            sourceMapFilename: "[name]/bundle.js.map",

        },
        module: {
            rules: [
                {
                    test: /(\.css|.scss)$/,
                    use: [{
                        loader: "style-loader" // creates style nodes from JS strings
                    }, {
                        loader: "css-loader" // translates CSS into CommonJS
                    }, {
                        loader: "sass-loader" // compiles Sass to CSS
                    }]
                },
                {
                    test: /\.(jsx|js)?$/,
                    use: [{
                        loader: "babel-loader",
                        // options: {
                        //     cacheDirectory: true,
                        //     presets: ['react', 'es2015'] // Transpiles JSX and ES6
                        // }
                    }]
                }
            ],

        },
        "plugins": [
            new CopyWebpackPlugin([
                {
                    from: 'src/public/app1/index.html',
                    to: 'app1'
                },
                {
                    from: 'src/public/app2/index.html',
                    to: 'app2'
                },
                {
                    from: 'src/public/app3/index.html',
                    to: 'app3'
                },
            ]),

        ]

    }
];

Я добавил свои настройки babelrc и webpack.Пожалуйста, дайте мне знать, если я что-то упустил, что может привести к появлению этой ошибки в консоли моего браузера.

Ответы [ 2 ]

0 голосов
/ 30 мая 2019

Добавление полифилов из create-react-app сработало для меня.

yarn add --dev react-app-polyfill

Затем добавьте следующие строки в webpack.config.js

entry: {
  app: [
    'react-app-polyfill/ie9', // Only if you want to support IE 9
    'react-app-polyfill/stable',
    './src/index.jsx',
  ],
},

См. Больше примеров на реагироватьapp-polyfill GitHub page .

0 голосов
/ 02 февраля 2019

Вы не включили свой файл package.json, поэтому немного неясно, чего вам не хватает.

Предполагая, что в вашем файле package.json есть @babel/polyfill в качестве зависимости, возможно ли, чтовы не указываете:

import '@babel/polyfill'

в вашем файле React (например, index.js)?

...