react-app-rewired breaks w/ react-scripts 2.1.2

Created on 23 Dec 2018  路  12Comments  路  Source: timarney/react-app-rewired

react-scripts 2.1.2+ has only one webpack.config.js now (prod + dev are configs are combined into one). This breaks react-app-rewired because it looks for webpack.config.prod.js

I know this module is no longer maintained, but up to this point (react-scripts 2.1.1 or earlier) it still allows you to manually modify parts of the config without issues. Just a heads up for anymore who may ran into this issue.

Most helpful comment

346 is now merged.

You can test using

yarn add [email protected]

Next steps:

  • Remove the built in rewires i.e. getLoader
  • Update the docs
  • Release a major version with the changes

All 12 comments

https://github.com/arackaf/customize-cra seems to rely on this package as well

I can resolve this issue with update source code for 2 files as below:

start.js

process.env.NODE_ENV = process.env.NODE_ENV || "development";

const paths = require("./utils/paths");
const overrides = require('../config-overrides');
const webpackConfigPath = paths.scriptVersion + "/config/webpack.config";
const devServerConfigPath = paths.scriptVersion + "/config/webpackDevServer.config.js";

// load original configs
const configFactory = require(webpackConfigPath);
const devServerConfig = require(devServerConfigPath);

// override config in memory
require.cache[require.resolve(webpackConfigPath)].exports =
  (NODE_ENV) => overrides.webpack(configFactory(NODE_ENV), process.env.NODE_ENV || NODE_ENV);

require.cache[require.resolve(devServerConfigPath)].exports =
  overrides.devServer(devServerConfig, process.env.NODE_ENV);

// run original script
require(paths.scriptVersion + "/scripts/start");

build.js

process.env.NODE_ENV = 'production';

const paths = require('./utils/paths');
const overrides = require('../config-overrides');
const webpackConfigPath = paths.scriptVersion + "/config/webpack.config";

// load original config
const configFactory = require(webpackConfigPath);

// override config in memory
require.cache[require.resolve(webpackConfigPath)].exports =
  (NODE_ENV) => overrides.webpack(configFactory(NODE_ENV), process.env.NODE_ENV || NODE_ENV);

// run original script
require(paths.scriptVersion + '/scripts/build');

@bugzpodder
Just switch to craco JS (it's crafted for CRA V2) Well as said below, it's broken too...
https://github.com/sharegate/craco

@AndyOGo Currently also broken with CRA v2.1.2: https://github.com/sharegate/craco/issues/61

@AndyOGo Currently also broken with CRA v2.1.2: sharegate/craco#61

yep, i got it in CRA V2.1.2 .

is there some solutions?

image

@alejandronanez simply stick to the v2.1.1 and wait for fix. There is no other workaround possible here.

oh...god.
in CRA 2.1.3 also got this problem .:(

seems rescripts is working:
https://github.com/rescripts/rescripts

346 is now merged.

You can test using

yarn add [email protected]

Next steps:

  • Remove the built in rewires i.e. getLoader
  • Update the docs
  • Release a major version with the changes

Just pushed 2.0.1 to npm thanks @tiffon for the PR + testing.

Thank you so much Tim and @tiffon for quick resolution. Life saver for me !

Was this page helpful?
0 / 5 - 0 ratings