【问题标题】:React + Webpack: "RuntimeError: memory access out of bounds"React + Webpack:“RuntimeError:内存访问越界”
【发布时间】:2020-09-03 22:12:50
【问题描述】:

我最近开发了一个 react + webpack 应用程序,使用 AWS 放大。我在 Sentry 上遇到了一个奇怪的错误,但不能 找到复制错误的方法。

RuntimeError: memory access out of bounds

我怀疑这与我的 webpack 配置有关,但我不知道出了什么问题。 我从未使用过wasm,但它似乎与它有关。

这是我的生产级 webpack 配置。

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const env = require('../environment/prod.env');
const commonPaths = require('./paths');
const webpack = require('webpack');
const SentryWebpackPlugin = require('@sentry/webpack-plugin');

module.exports = {
    mode: 'production',
    devtool: 'source-map',
    output: {
        filename: `${commonPaths.jsFolder}/[name].[hash].js`,
        path: commonPaths.outputPath,
        chunkFilename: `${commonPaths.jsFolder}/[name].[chunkhash].js`,
    },
    optimization: {
        minimizer: [
            new TerserPlugin({
                parallel: true,
                cache: true,
                sourceMap: true,
            }),
            new OptimizeCSSAssetsPlugin(),
        ],

        splitChunks: {
            cacheGroups: {
                vendors: {
                    test: /[\\/]node_modules[\\/]/,
                    name: 'vendors',
                    chunks: 'initial',
                },
                async: {
                    test: /[\\/]node_modules[\\/]/,
                    name: 'async',
                    chunks: 'async',
                    minChunks: 4,
                },
            },
        },
        runtimeChunk: true,
    },

    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [
                    { loader: 'style-loader' },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                    {
                        loader: 'sass-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                ],
            },
            {
                test: /\.css$/,
                use: [
                    {
                        loader: 'style-loader',
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                ],
            },
        ],
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': env,
        }),
        new MiniCssExtractPlugin({
            filename: `${commonPaths.cssFolder}/[name].css`,
            chunkFilename: `${commonPaths.cssFolder}/[name].css`,
        }),
    ],
};

这里也是我常用的webpack配置

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const commonPaths = require('./paths');

module.exports = {
    context: commonPaths.srcPath,
    entry: commonPaths.entryPath,
    output: {
        path: commonPaths.outputPath,
        filename: 'js/[name].js',
    },
    resolve: {
        extensions: ['.ts', '.js', '.html', '.vue'],
        alias: {
            '~': commonPaths.srcPath,
        },
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                include: commonPaths.srcPath,
                exclude: /node_modules/,
                loader: 'babel-loader',
                options: {
                    plugins: ['react-hot-loader/babel'],
                },
            },
            {
                test: /\.(png|jpg|gif|svg)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: 'assets/img/[name].[hash:8].[ext]',
                            publicPath: '/',
                        },
                    },
                ],
            },
            {
                test: /\.(mp3)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: 'assets/audio/[name].[hash:8].[ext]',
                            publicPath: '/',
                        },
                    },
                ],
            },
            {
                test: /\.(ttc|ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: 'assets/fonts/[name].[hash:8].[ext]',
                            publicPath: '/',
                        },
                    },
                ],
            },
        ],
    },
    serve: {
        content: commonPaths.entryPath,
        dev: {
            publicPath: commonPaths.outputPath,
        },
        open: true,
    },
    resolve: {
        modules: ['src', 'node_modules', 'bower_components', 'shared', '/shared/vendor/modules'],
        extensions: ['*', '.js', '.jsx'],
    },
    plugins: [
        new webpack.ProgressPlugin(),
        new HtmlWebpackPlugin({
            favicon: './icon.png',
            template: commonPaths.templatePath,
        }),
        new ScriptExtHtmlWebpackPlugin({
            defaultAttribute: 'async',
        }),
    ],
};

任何帮助都会有帮助。谢谢。

【问题讨论】:

    标签: javascript reactjs google-chrome webpack


    【解决方案1】:

    尝试重新启动服务器并确保重新安装节点模块。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2021-10-06
    • 2021-10-26
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2021-09-10
    相关资源
    最近更新 更多