Open CiprianDraghici opened 7 months ago
One more way of solving this is:
Adding react-app-rewired
as a dev dependency
Adding a config-overrides.js
file with this code:
const getCacheIdentifier = require("react-dev-utils/getCacheIdentifier");
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== "false";
module.exports = function override(config, webpackEnv) {
console.log("overriding webpack config...");
const isEnvDevelopment = webpackEnv === "development";
const isEnvProduction = webpackEnv === "production";
const loaders = config.module.rules[1].oneOf;
loaders.splice(loaders.length - 1, 0, {
test: /\.(js|mjs|cjs)$/,
exclude: /@babel(?:\/|\\{1,2})runtime/,
loader: require.resolve("babel-loader"),
options: {
babelrc: false,
configFile: false,
compact: false,
presets: [[require.resolve("babel-preset-react-app/dependencies"), { helpers: true }]],
cacheDirectory: true,
// See #6846 for context on why cacheCompression is disabled
cacheCompression: false,
// @remove-on-eject-begin
cacheIdentifier: getCacheIdentifier(isEnvProduction ? "production" : isEnvDevelopment && "development", [
"babel-plugin-named-asset-import",
"babel-preset-react-app",
"react-dev-utils",
"react-scripts",
]),
// @remove-on-eject-end
// Babel sourcemaps are needed for debugging into node_modules
// code. Without the options below, debuggers like VSCode
// show incorrect code and set breakpoints on the wrong lines.
sourceMaps: shouldUseSourceMap,
inputSourceMap: shouldUseSourceMap,
},
});
return config;
};
react-scripts
to react-app-rewired
One more thought on this.
One should install @craco/craco instead of simply craco (that's the official package)
As a workaround please check this thread: https://github.com/facebook/create-react-app/issues/12700#issuecomment-1463040093
ex.
craco
add dev dependencyyarn add -D @craco/craco
craco.config.js
file on the project rootbuild
and (or)start
scripts inpackage.json
by replacingreact-scripts
withcraco
. Check the docs for further details: https://github.com/dilanx/craco