2

AWS 开发工具包抛出

Uncaught TypeError: Cannot read property 'crypto' of undefined
    at eval (rng.js:23)
    at eval (rng.js:32)
    at Object../node_modules/crypto-browserify/rng.js (main.js:13413)
    at __webpack_require__ (main.js:20)
    at eval (index.js:6)
    at Object../node_modules/crypto-browserify/index.js (main.js:13389)
    at __webpack_require__ (main.js:20)
    at eval (AuthenticationHelper.js:9)
    at Object../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (main.js:238)
    at __webpack_require__ (main.js:20)

我在我的反应应用程序中使用 aws-amplify 作为依赖项

查看现有的类似问题,我发现通过在 babel 加载程序的排除列表中添加“node_module”文件夹来解决问题,但这不适用于我的情况。

这是 webpack 配置文件。

const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.html$/,
                use: [
                    {
                        loader: "html-loader",
                        options: {minimize: true}
                    }
                ]
            },
            {
                test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
                use: [{
                    loader: 'file-loader',
                    options: {
                        name: '[name].[ext]',
                        outputPath: 'fonts/'
                    }
                }]
            },
            {
                test: /\.css$/,
                use: [MiniCssExtractPlugin.loader, "css-loader"]
            }
        ]
    },
    plugins: [
        new HtmlWebPackPlugin({
            template: "./src/index.html",
            filename: "./index.html"
        }),
        new MiniCssExtractPlugin({
            filename: "[name].css",
            chunkFilename: "[id].css"
        })
    ]
};
4

0 回答 0