Amplify JS SDK抛出Uncaught TypeError:无法读取属性' crypto'未定义的

时间:2018-05-23 13:16:57

标签: javascript reactjs aws-sdk aws-cognito aws-amplify

AWS SDK抛出

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作为依赖

看看现有的类似问题,我发现问题是通过添加" node_module"来解决的。 babel loader的排除列表中的文件夹,但在我的情况下这不起作用。

这是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"
        })
    ]
};

0 个答案:

没有答案