Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk-dapp versions >= 2.25.2 is not supported in CRA projects due to axios >= 1.x used by various @multiversx sdks #999

Open
CiprianDraghici opened this issue Dec 20, 2023 · 2 comments
Labels

Comments

@CiprianDraghici
Copy link
Contributor

CiprianDraghici commented Dec 20, 2023

As a workaround please check this thread: facebook/create-react-app#12700 (comment)

ex.

  1. Add craco add dev dependency
    yarn add -D @craco/craco
  2. Create craco.config.js file on the project root
module.exports = {
  webpack: {
    configure: config => ({
      ...config,
      module: {
        ...config.module,
        rules: config.module.rules.map(rule => {
          if (rule.oneOf instanceof Array) {
            // eslint-disable-next-line no-param-reassign
            rule.oneOf[rule.oneOf.length - 1].exclude = [
              /\.(js|mjs|jsx|cjs|ts|tsx)$/,
              /\.html$/,
              /\.json$/,
            ];
          }
          return rule;
        }),
      },
    }),
  },
};
  1. Change the build and (or) start scripts in package.json by replacing react-scripts with craco.
    Check the docs for further details: https://github.com/dilanx/craco
@CiprianDraghici CiprianDraghici added help wanted Extra attention is needed wontfix This will not be worked on and removed help wanted Extra attention is needed labels Dec 20, 2023
@CiprianDraghici CiprianDraghici changed the title sdk-dapp versions >= 2.25.2 is not supported in CRA projects due to axios >= 1.2.2 used by various @multiversx sdks sdk-dapp versions >= 2.25.2 is not supported in CRA projects due to axios >= 1.x used by various @multiversx sdks Dec 20, 2023
@arhtudormorar arhtudormorar added FIXED and removed wontfix This will not be worked on labels Dec 21, 2023
@damienen
Copy link

damienen commented Dec 21, 2023

One more way of solving this is:

  1. Adding react-app-rewired as a dev dependency

  2. 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;
};
  1. Change react-scripts to react-app-rewired

@damienen
Copy link

One more thought on this.

One should install @craco/craco instead of simply craco (that's the official package)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants