0

我正在尝试使用 react-app-rewired 构建我的 react 项目,当我运行 yarn build 命令时,它在 package.json 中定义如下:

"scripts": {
   "start": "react-app-rewired start",
   "build": "react-app-rewired --max_old_space_size=4096 --expose-gc build",
}

在纱线构建后的控制台上:

yarn build       
yarn run v1.22.10
$ react-app-rewired --max_old_space_size=4096 --expose-gc build
PRODUCTION ENVIRONMENT ENABLED
Creating an optimized production build...
(node:7104) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.h
ooks` instead
Failed to compile.

this.config.reduce is not a function


error Command failed with exit code 1.

我的 config-overrides.js :


const rewireDev = require('j1r-react-scripts/j1r-scripts/config.dev');
const rewireProd = require('j1r-react-scripts/j1r-scripts/config.prod');
const fs = require('fs');
const path = require('path');
const cspConfiguration = require('./csp-configuration.json');
const j1r = require('j1r-react-scripts/j1r-scripts/plugins');
const rewireBabelLoader = require('react-app-rewire-babel-loader');

const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);

process.env['SKIP_PREFLIGHT_CHECK'] = process.env['SKIP_PREFLIGHT_CHECK'] || true;

module.exports = {
  webpack: (config, env) => {
    //  alias(configPaths())(config);
    config = rewireBabelLoader.include(config, resolveApp('../common'));

    switch (env) {
      case 'development': {
        console.log('DEVELOPMENT ENVIRONMENT ENABLED');
        let options = {
          matcher: {
            dev: /app\.json$/,
            mocked: /mocked\.json$/,
          },
          href: 'config/app.json',
        };

        return rewireDev(config, options);
      }
      case 'production': {
        console.log('PRODUCTION ENVIRONMENT ENABLED');
        config.plugins.push(new j1r.CspHashPlugin(cspConfiguration));
        return rewireProd(config);
      }
      default: {
        console.error('UNKNOWN ENVIRONMENT ENABLED [%s]', env);
      }
    }

    return config;
  },

};

我不明白这个问题,如果我启动应用程序它没有问题,只是构建失败......有人可以帮助我吗?谢谢

4

0 回答 0