440

webpack 5 no longer do auto-polyfilling for node core modules. How to fix it please?

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

errors

4

37 Answers 37

173

I was also getting these error's when upgrading from webpack v4 to v5. Resolved by making the following changes to webpack.config.js

added resolve.fallback property

removed node property

{
resolve: {
  modules: [...],
  fallback: {
    "fs": false,
    "tls": false,
    "net": false,
    "path": false,
    "zlib": false,
    "http": false,
    "https": false,
    "stream": false,
    "crypto": false,
    "crypto-browserify": require.resolve('crypto-browserify'), //if you want to use this module also don't forget npm i crypto-browserify 
  } 
},
entry: [...],
output: {...},
module: {
  rules: [...]
},
plugins: [...],
optimization: {
  minimizer: [...],
},
// node: {
//   fs: 'empty',
//   net: 'empty',
//   tls: 'empty'
// },
}

upgrade from v4 to v5 => https://webpack.js.org/migrate/5/#clean-up-configuration

12
  • 6
    What do you put in the node_modules : [...] ? Commented Feb 19, 2021 at 0:34
  • 3
    @Ruik usually we set webpack configs in webpack.config.js file in the root folder of your app. webpack.js.org/configuration Commented Sep 10, 2021 at 10:30
  • 7
    @MaqsoodAhmed I do not appear to have this file (webpack.config.js) in the root folder of my app???
    – johnDoe
    Commented Feb 12, 2022 at 10:06
  • 8
    @johnDoe I think you created project using create-react-app. So, you can may get config file by ejecting project OR by going into react-scripts node_modules folder. stackoverflow.com/questions/48395804/… Commented Feb 12, 2022 at 10:51
  • 3
    Thanks so much! I went from 190 errors to five firebase-related errors and one google auth error. This is a lot more manageable.
    – brohjoe
    Commented Apr 21, 2022 at 14:01
127

Re-add support for Node.js core modules with node-polyfill-webpack-plugin:

With the package installed, add the following to your webpack.config.js:

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

module.exports = {
    // Other rules...
    plugins: [
        new NodePolyfillPlugin()
    ]
}
8
  • 22
    This fixed most of the errors, but not all. I still needed to fix 'fs' and 'path-browserify' using @lukas-bach 's solution. Commented Jan 20, 2021 at 22:13
  • 3
    @kenecaswell I'm open to suggestions for improvement. How should fs be polyfilled in the browser? Should we just lie with a shim? Commented Jan 21, 2021 at 1:39
  • 3
    I take back what I said, node-polyfill-webpack-plugin worked great for my client bundling. I was also bundling server side code which needed 'fs' and 'path-browserify'. Once I applied your plugin to only my client build it worked great. Commented Feb 1, 2021 at 23:52
  • 4
    everyone keeps mentioning webpack.config.js file, I cannot find it in the root folder of my app. Please can soneone advise?
    – johnDoe
    Commented Feb 12, 2022 at 10:03
  • 3
    @johnDoe if you are using create-react-app, the webpack.config.js can be found in node_modules/react-scripts (stackoverflow.com/a/48396154/3563737). To edit the webpack configuration of a CRA project, you might want to consider the react-app-rewired package (npmjs.com/package/react-app-rewired).
    – Wasbeer
    Commented Feb 28, 2022 at 7:04
100

I think most the answers here would resolve your issue. However, if you don't need Polyfills for your node development, then I suggest using target: 'node' in your Webpack module configuration. This helped resolve the issue for me.

Here is some documentation on the answer: https://webpack.js.org/concepts/targets/

enter image description here

5
  • 5
    It works well for Node 16.*.*
    – hastrb
    Commented Nov 27, 2021 at 14:34
  • 5
    doesn't work for node 14.0.0 Commented Dec 27, 2021 at 7:47
  • this didn't worked for me it crashed completely my app, some error about bundling
    – codmitu
    Commented Aug 9, 2022 at 21:25
  • Resolve the errors but I got "require" is not defined in the browser console.
    – Dotista
    Commented Dec 13, 2022 at 11:37
  • 2
    Worked well for Node v18.12.1 Commented Jan 15, 2023 at 6:23
85

As per Web3 documentation:

If you are using create-react-app version >=5 you may run into issues building. This is because NodeJS polyfills are not included in the latest version of create-react-app.

Solution:

Install react-app-rewired and the missing modules

If you are using yarn:

yarn add --dev react-app-rewired crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process

If you are using npm:

npm install --save-dev react-app-rewired crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process

Create config-overrides.js in the root of your project folder with the content:

const webpack = require('webpack');

module.exports = function override(config) {
    const fallback = config.resolve.fallback || {};
    Object.assign(fallback, {
        "crypto": require.resolve("crypto-browserify"),
        "stream": require.resolve("stream-browserify"),
        "assert": require.resolve("assert"),
        "http": require.resolve("stream-http"),
        "https": require.resolve("https-browserify"),
        "os": require.resolve("os-browserify"),
        "url": require.resolve("url")
    })
    config.resolve.fallback = fallback;
    config.plugins = (config.plugins || []).concat([
        new webpack.ProvidePlugin({
            process: 'process/browser',
            Buffer: ['buffer', 'Buffer']
        })
    ])
    return config;
}

Within package.json change the scripts field for start, build and test. Instead of react-scripts replace it with react-app-rewired before:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
},

after:

"scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
},

The missing Nodejs polyfills should be included now and your app should be functional with web3.

If you want to hide the warnings created by the console:

In config-overrides.js within the override function, add:

config.ignoreWarnings = [/Failed to parse source map/];
8
  • 4
    This helped I added the config-overrides file to my root and then called crypto in a js file in src folder. When I did that I got the error: Module not found: Error: You attempted to import /Users/username/abja/identity/node_modules/crypto-browserify/index.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
    – Mabel Oza
    Commented Apr 17, 2022 at 15:40
  • its work for me Commented Apr 26, 2022 at 7:48
  • 1
    It doesn't work for me: Module not found: Error: Can't resolve 'process/browser' in '/Users/bartolini/workspace-osa/osa-web-ui/node_modules/axios/lib/defaults' Did you mean 'browser.js'? BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified Commented Oct 14, 2022 at 8:48
  • Also got this but in another lib (dependency of react-markdown): Module not found: Error: Can't resolve 'process/browser' in '...\node_modules\uvu\node_modules\kleur' Did you mean 'browser.js'? BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
    – Paintoshi
    Commented Jan 23, 2023 at 18:03
  • Only thing that worked after hours(days?) of searching everywhere. This should be marked as the accepted answer IMO
    – LeandroG
    Commented Mar 16, 2023 at 18:27
40

I faced this issue with create-react-app which by default gave me

"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.2"

I fixed it by just changing react-scripts to version 4.0.3.

5
  • 3
    This worked for me. Its a temp solution, but successful for now.
    – Luke Dupin
    Commented Dec 26, 2021 at 21:31
  • 1
    The only thing that worked for me, thanks ! Nice temporary fix until it breaks, by which time there will hopefully be a more up-to-date solution.
    – user1300214
    Commented Jan 29, 2022 at 13:56
  • 2
    This worked for me as well, I don't have webpack integration in our app yet so this is the best solution for me.
    – Ronnie
    Commented Feb 22, 2022 at 19:53
  • Downgrading to 4.0.3 worked for me as well
    – Ashiq Dey
    Commented Jul 10, 2022 at 4:57
  • With react 18 i get 20 more vulnerabilities with 4.0.3 than 5.0.1
    – codmitu
    Commented Aug 9, 2022 at 21:32
33

Looks like you've used the path package which is not included in webpack builds by default. For me, extending the webpack config like this helped:

{
  // rest of the webpack config
  resolve: {
    // ... rest of the resolve config
    fallback: {
      "path": require.resolve("path-browserify")
    }
  },
}

Also install path-browserify via npm install path-browserify --save-dev or yarn add path-browserify --dev if you're using yarn.

2
  • If it will be shipped to the browser, should it be a dev dependency?
    – MkMan
    Commented Mar 11, 2021 at 21:27
  • 4
    @MMansour if you build your app as a webpack project and just ship the built artifacts, it shouldn't matter. Differentiation between dev and normal dependencies is only relevant if you publish your package to NPM, in which case consumers of your package will only install non-dev dependencies.
    – Lukas Bach
    Commented Mar 12, 2021 at 0:09
25

You need React => v17 React scripts=> v5 webpack => v5

To Fix The Problem

1) Install

"fs": "^2.0.0",  // npm i fs
"assert": "^2.0.0",  // npm i assert
"https-browserify": "^1.0.0", // npm i https-browserify
"os": "^0.1.2", // npm i os
"os-browserify": "^0.3.0", // npm i os-browserify
"react-app-rewired": "^2.1.9", //npm i react-app-rewired
"stream-browserify": "^3.0.0", // stream-browserify
"stream-http": "^3.2.0", //stream-http

2) Creating config-overrides.js in root directory Image

3) Add configs to config-overrides.js

const webpack = require('webpack');
module.exports = function override(config, env) {
    config.resolve.fallback = {
        url: require.resolve('url'),
        fs: require.resolve('fs'),
        assert: require.resolve('assert'),
        crypto: require.resolve('crypto-browserify'),
        http: require.resolve('stream-http'),
        https: require.resolve('https-browserify'),
        os: require.resolve('os-browserify/browser'),
        buffer: require.resolve('buffer'),
        stream: require.resolve('stream-browserify'),
    };
    config.plugins.push(
        new webpack.ProvidePlugin({
            process: 'process/browser',
            Buffer: ['buffer', 'Buffer'],
        }),
    );

    return config;
}

3) Change packages.json

"scripts": {
  "start": "react-app-rewired start",
  "build": "react-app-rewired build",
  "test": "react-app-rewired test",
  "eject": "react-app-rewired eject"
}

Problem solved :)

6
  • no need fir /browser in => os: require.resolve('os-browserify/browser'),
    – David Peer
    Commented Jan 30, 2022 at 13:23
  • this fix it for me.
    – S. N
    Commented Feb 9, 2022 at 11:20
  • Worked for meee! Thank you so much. I was searching for a fix like hell for an hour
    – csgeek
    Commented May 14, 2022 at 21:20
  • 4
    fs does'nt seem to be polyfilled. npm i fs does'nt seem to work,package is in security holding. Commented Jun 12, 2022 at 8:00
  • 1
    Docs for react-app-rewired say "Do NOT flip the call for the eject script"
    – Octopus
    Commented Sep 21, 2022 at 18:14
18

Create React App just released v5 which now implements Webpack v5. This is going to fully break many libraries which includes web3 as the required Node core library polyfills will be missing.

To resolve this quickly you can change this in your package.json:

"react-scripts": "^5.0.0"

To this

"react-scripts": "4.0.3"

After this:

rm -r node_modules

rm package-lock.json

npm install
2
15

It happen with me while I reinstall the node modules my webpack current version is 5.38.1, I have fixed the issue with npm i path-browserify -D after installation you have to update your webpack.config.js resolve{} with fallback: {"fs": false, "path": require.resolve("path-browserify")} while not using "fs": false it show errors i.e: Module not found: Error: Can't resolve 'fs' in '/YOUR DIRECTORY ...' so don't forget to add it; with other stuff it look like:

module.exports = {
   ...
   resolve: {
    extensions: [".js", ".jsx", ".json", ".ts", ".tsx"],// other stuff
    fallback: {
      "fs": false,
      "path": require.resolve("path-browserify")
    }
  },
};

remove node property if it exist in your webpack.config.js file

1
10

Method 1

  • Open project/node_modules/react-scripts/config/webpack.config.js

  • In fallback add "crypto": require.resolve("crypto-browserify")

resolve: {
   fallback: {
       "crypto": require.resolve("crypto-browserify")
   }
} 
  • Install npm i crypto-browserify
  • Restart your app.

Above method doesn't work if you commit since we aren't node_modules

Method 2

  • Install patch-package: yarn add patch-package

  • Install the needed pollyfills.(do an initial build of your application and it will tell you.)

  • Modify node_modules/react-scripts/config/webpack.config.js. Here's an example. This is taken from Webpack's docs.

module.exports = {
  //...
  resolve: {
    fallback: {
      assert: require.resolve('assert'),
      buffer: require.resolve('buffer'),
      console: require.resolve('console-browserify'),
      constants: require.resolve('constants-browserify'),
      crypto: require.resolve('crypto-browserify'),
      domain: require.resolve('domain-browser'),
      events: require.resolve('events'),
      http: require.resolve('stream-http'),
      https: require.resolve('https-browserify'),
      os: require.resolve('os-browserify/browser'),
      path: require.resolve('path-browserify'),
      punycode: require.resolve('punycode'),
      process: require.resolve('process/browser'),
      querystring: require.resolve('querystring-es3'),
      stream: require.resolve('stream-browserify'),
      string_decoder: require.resolve('string_decoder'),
      sys: require.resolve('util'),
      timers: require.resolve('timers-browserify'),
      tty: require.resolve('tty-browserify'),
      url: require.resolve('url'),
      util: require.resolve('util'),
      vm: require.resolve('vm-browserify'),
      zlib: require.resolve('browserify-zlib'),
    },
  },
};
  • Don't add all of them, add only the ones you need.

Make sure you install the packages first before modifying the webpack config.

  • Run yarn patch-package react-scripts. This will generate a patch (this should be committed in your repo going forward).

  • Add a postinstall script to package.json: "postinstall": "yarn patch-package". Now, anytime, someone installs npm deps on this project, will get the patch you created in step 3 applied automatically.

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "postinstall": "yarn patch-package"
  },
2
  • 12
    Method 1 is very bad. Never recommend changing something in node_modules!!
    – BonisTech
    Commented Apr 10, 2022 at 22:15
  • Method 2 does not work for process. See other answers that use ProvidePlugin.
    – Lawrence
    Commented Oct 18, 2022 at 4:52
9

My solution for #VUE

const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack');
module.exports = defineConfig({
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        Buffer: ['buffer', 'Buffer'],
      }),
      new webpack.ProvidePlugin({
          process: 'process/browser',
      })
    ],
    resolve: {
      fallback: {
        "os": require.resolve("os-browserify/browser"),
        "url": require.resolve("url/"),
        "crypto": require.resolve("crypto-browserify"),
        "https": require.resolve("https-browserify"),
        "http": require.resolve("stream-http"),
        "assert": require.resolve("assert/"),
        "stream": require.resolve("stream-browserify"),
        "buffer": require.resolve("buffer")
      }
    }
  },

  transpileDependencies: [
    'vuetify'
  ]

})
3
  • 2
    It saves me in my vue 2 project Commented Sep 6, 2022 at 14:23
  • What is this file? Commented Oct 2, 2023 at 19:53
  • 1
    @CameronHudson it is vue.config.js
    – Magnetto90
    Commented Oct 12, 2023 at 21:20
6

My environment is like this:

  • React => v17
  • React scripts=> v5
  • webpack => v5

To Fix The Problem follow the below instructions

1- Install below packages

yarn add fs assert https-browserify os os-browserify stream-browserify stream-http react-app-rewired

2- Create config-coverrides.js in Root dir of your project next to the package.json

add the below code to it:

const webpack = require('webpack');
module.exports = function override(config, env) {
    config.resolve.fallback = {
        url: require.resolve('url'),
        fs: require.resolve('fs'),
        assert: require.resolve('assert'),
        crypto: require.resolve('crypto-browserify'),
        http: require.resolve('stream-http'),
        https: require.resolve('https-browserify'),
        os: require.resolve('os-browserify/browser'),
        buffer: require.resolve('buffer'),
        stream: require.resolve('stream-browserify'),
    };
    config.plugins.push(
        new webpack.ProvidePlugin({
            process: 'process/browser',
            Buffer: ['buffer', 'Buffer'],
        }),
    );

    return config;
}

3- Change the packages.js like the below

  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-app-rewired eject"
  },

3
  • Your clean explanation however, gives a memory issue when in CI/CD of Gitlab, it uses significantly more memory than without the react-app-rewired trick. At the end, I had to downgrade to react-scripts 4.0.3 again
    – user2410689
    Commented Feb 27, 2022 at 19:37
  • Of all those options, this was the only worked properly. Simply downgrading react-scripts to 4.0 on my scenario wasn't a solution since it was breaking all the Tailwind stuff that I am using. Commented Jun 22, 2022 at 21:44
  • The docs for react-app-rewired say "Do NOT flip the call for the eject script." in other words, leave "eject" as "react-scripts eject".
    – Octopus
    Commented Sep 21, 2022 at 18:57
5

npm install path-browserify and then try to change webpack configuration to include:

module.exports = {
    ...
    resolve: {
        alias: {
            path: require.resolve("path-browserify")
        }
    }
};
5

I'm using create-react-app with craco, and I encountered the following errors when upgrading to webpack 5:

'buffer'


Module not found: Error: Can't resolve 'buffer' in '/Users/therightstuff/my-project/node_modules/safe-buffer'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
    - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "buffer": false }

This was resolved simply by installing the buffer package with npm install -D buffer.

'fs'


Module not found: Error: Can't resolve 'fs' in '/Users/therightstuff/my-project/node_modules/line-navigator'

This was resolved by setting a webpack fallback in the craco configuration craco.config.js:

module.exports = {
    style: {
        postcssOptions: {
            plugins: [
            require('tailwindcss'),
            require('autoprefixer'),
            ],
        },
    },
    webpack: {
        configure: (webpackConfig, { env, paths }) => {
            // eslint-disable-next-line no-param-reassign
            webpackConfig.resolve.fallback = {
                fs: false,
            };
            return webpackConfig;
        },
    },
}
1
  • 1
    fs: false, worked for me!! i used config-overrides.js though. Commented Aug 7, 2022 at 6:44
2

you want to used in

const nodeExternals = require('webpack-node-externals');

add in webpack.config.js

target: "node",
devtool: "source-map",
externals: [nodeExternals()],
2
  • 3
    please take time to read this: stackoverflow.com/help/how-to-answer
    – user14709104
    Commented Apr 15, 2021 at 13:01
  • for webpack 5: replace target: node by externalsPresets: { node: true },
    – Dotista
    Commented Dec 13, 2022 at 14:13
2

This is happening with the new vue-cli upgrade (v5). In order to fix it (the empty modules way), you have to change vue.config.js this way:

configureWebpack: (config) => {
  config.resolve.fallback = {
    ...config.resolve.fallback,
    // Include here the "empty" modules
    url: false,
    util: false,
    querystring: false,
    https: false,
  };
}
2

I found a solution that worked for me:

  1. npm uninstall webpack
  2. delete the "package-lock.json" file
  3. npm install [email protected] --force
  4. include in the "package.json" file the following in your "scripts":
    "scripts": {
        "start": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
        "build": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    }
    
1
  • Finally. This one works for me. I only want to use dotenv, but man.. it hurt
    – swdev
    Commented Apr 8, 2023 at 9:55
2

All other answers are missing one important piece: how NOT to polyfill the node core modules. In case the error comes from some module in dependency of dependency of your dependency, which you actually do not need, you can quite safely ignore it. In that case, the most simple workaround is to add to your package.json these lines:

"browser": {
  "fs": false,
  "path": false,
  "os": false
}

And similarly for other core node modules if you need to ignore them.

This approach works great for frameworks where the actual webpack config is not directly accessible by default (like Angular).

I have found this solution when looking for a different error.

2

For those still doing configuration through react-app-rewired's config-overrides.js file, this will work:

config-overrides.js

const { override, addWebpackPlugin } = require('customize-cra')
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

module.exports = override(addWebpackPlugin(new NodePolyfillPlugin()))

package.json

...
"dependencies": {
    ...
    "customize-cra": "^1.0.0",
    "node-polyfill-webpack-plugin": "^2.0.1"
  },

This will inject node-polyfill-webpack-plugin as a webpack 5 plugin.

1
npm install assert --save

npm install buffer --save

For anyone facing similar issue, just install the missing modules. These modules are reported as missing because they are part of node.js, but are available separately also via the npm.

1
  • Does not work. Just installing a module, does not cause it to be included and called, webpack excludes unused code.
    – user2410689
    Commented Feb 24, 2022 at 8:29
1

I got this error while imported Router from express import { Router } from 'express';

Resolved after correction import { Router } from '@angular/router';

1

Faced the same issue, here's a solution:

  1. Remove package-lock.json from the project folder and npm uninstall webpack
  2. Downgrade react-script from to 4.0.3
  3. Make sure package-lock.json is deleted/removed
  4. Install webpack using npm install [email protected]
  5. Finally, run npm install using the terminal
1

I tried this https://stackoverflow.com/a/71803628/15658978 solution and it solved the problem form me.

simply run the following 2 commands

npm uninstall react-scripts
npm install [email protected]
1
  • Thanks @kennisnutz, this was the easiest fix for me. Just a small headache which I am just ignoring for now: I am using React 18.2 and after your suggested change my VSCode parser complains about import { useState } from "react"; "Parsing error: require() of ES Module gappscript\node_modules\eslint-scope\lib\index.js from gappscript\node_modules\babel-eslint\lib\require-from-eslint.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead" Commented Oct 14, 2022 at 18:42
1

I had a React.js and Firebase app and it was giving the same error. I solved my issue by removing require('dotenv').config();. New React.js versions automatically handles loading packages like dotenv.

This polyfill error is not only with dotenv package but also with some other packages. So, if you have some loading statements as above, you can remove them and retry again.

0

My app threw the same error yesterday. I spent hours reading questions/answers here on SO and trying some. What has worked for me is this:

https://github.com/ChainSafe/web3.js#troubleshooting-and-known-issues

0

If it's Twilio you use:

The Twilio module is not intended for use in client-side JavaScript, which is why it fails for your Angular application. Twilio uses your Account SID and your Auth Token, the use in the client side represents a risk; So the best is to use it on the server side and to use the API.

0

With create-react-app v17 and scripts 5.0.0 you need to add a fallback to your webpack.config.js and install 'process'.

   `module.exports = function (webpackEnv) {
      .........
      return {
       .........
      resolve: {
      ..........
      fallback: { "process": require.resolve("process/browser") },`
0

Secret's answer very nearly worked for me (I don't have enough reputation yet to comment on there, sorry!)

After having followed the steps in their answer it then told me that because of the difference in required versions of eslint, I should add SKIP_PREFLIGHT_CHECK=true to a .env file in the project, so I just added it to my existing one.

It would then successfully build (finally!) But then I noticed, in Chrome at least, that I couldn't click on anything or even select any text. Turns out that there's still an Iframe over the top of everything that can be removed in Inspector. - This applies when running a dev build, npm run start, I am not sure if it does it on a production build.

I must say this sudden change IMO really hasn't been very well thought through!

0

if you are using create-react-app with craco then configuration in craco.config.js should be like this:

module.exports = {
  webpack: {
      configure: {
        resolve: {
          fallback: {
            "path": require.resolve("path-browserify")
          },
        },
      },
    },
}
0

If you're having this error on your react app, webpack.config.js would not help you override the webpack config. You have to use craco to solve this and then run your project with craco ie

    craco.config.js

     const path = require('path');
     module.exports = {
      webpack: {
       configure: {
        resolve: {
         fallback: {
          crypto: require.resolve('crypto-browserify'),
         },
        },
       },
      },
     };

Then you run your react app on craco ie

    package.json
 
    "scripts": {
     "start": "craco start",
     "build": "craco build",
    },

Not the answer you're looking for? Browse other questions tagged or ask your own question.