首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义的ReferenceError:在通过操作进行api调用时,未在react 17、webpack 5中定义regeneratorRuntime。

未定义的ReferenceError:在通过操作进行api调用时,未在react 17、webpack 5中定义regeneratorRuntime。
EN

Stack Overflow用户
提问于 2020-12-29 03:47:24
回答 1查看 9.3K关注 0票数 10

在试图使用超级代理进行api调用时出现此错误Uncaught ReferenceError: regeneratorRuntime is not defined

目前,我使用的反应17,webpack 5连同css模块和所有最新的软件包。

package.json

代码语言:javascript
复制
{
  "dependencies": {
    "date-fns": "^2.16.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "superagent": "^6.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "@babel/preset-env": "^7.12.11",
    "@babel/preset-react": "^7.12.10",
    "@dr.pogodin/babel-plugin-react-css-modules": "^6.0.10",
    "babel-eslint": "^10.1.0",
    "babel-loader": "^8.2.2",
    "css-loader": "^5.0.1",
    "eslint": "^7.16.0",
    "html-webpack-plugin": "^5.0.0-beta.1",
    "mini-css-extract-plugin": "^1.3.3",
    "node-sass": "^5.0.0",
    "postcss": "^8.2.1",
    "postcss-scss": "^3.0.4",
    "sass": "^1.30.0",
    "sass-loader": "^10.1.0",
    "style-loader": "^2.0.0",
    "url-loader": "^4.1.1",
    "webpack": "^5.11.0",
    "webpack-cli": "^4.3.0",
    "webpack-dev-server": "^3.11.0"
  }
}

babel.config.js

代码语言:javascript
复制
module.exports = {
  presets: ["@babel/preset-env", "@babel/preset-react"],
  plugins: [
    [
      "@dr.pogodin/babel-plugin-react-css-modules",
      {
        webpackHotModuleReloading: true,
        autoResolveMultipleImports: true,
        filetypes: {
          ".scss": {
            syntax: "postcss-scss",
          },
        },
        generateScopedName:
          process.env.NODE_ENV === "development"
            ? "[path]___[name]__[local]___[hash:base64:5]"
            : "[hash:base64:5]",
      },
    ],
  ],
};

webpack.config.js

代码语言:javascript
复制
module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ["babel-loader"],
      },
      {
        test: /\.(css|sass|scss)$/,
        exclude: /node_modules/,
        use: [
          isDev ? "style-loader" : MiniCssExtractPlugin.loader,
          {
            loader: "css-loader",
            options: {
              modules: {
                auto: (resourcePath) =>
                  resourcePath.indexOf("assets/stylesheets") === -1,
                localIdentName: isDev
                  ? "[path]___[name]__[local]___[hash:base64:5]"
                  : "[hash:base64:5]",
              },
              sourceMap: isDev,
            },
          },
          "sass-loader",
        ],
      }
    ],
  },

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-29 07:20:02

对于Babel 7,安装这两个依赖项:

代码语言:javascript
复制
npm install --save @babel/runtime 
npm install --save-dev @babel/plugin-transform-runtime

在.babelrc中添加:

代码语言:javascript
复制
{
    "presets": ["@babel/preset-env"],
    "plugins": [
        ["@babel/plugin-transform-runtime"]
    ]
}
票数 31
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65487071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档