'Just after installing uuidv4, it shows error which is as follows:

one ERROR in ./node_modules/util/util.js

Module build failed (from ./node_modules/source-map-loader/dist/cjs.js): Error: ENOENT: no such file or directory, open 'C:\Users\shivani_sahu\dm-reactpjt\contact-app\node_modules\util\util.js'

Seeing utiL, I thought to install util by npm install util but then it again show an error which is as follows: To solve it: npm install util, and add it into webpack.config.js:

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: { "util": require.resolve("util/") }', install 'util'; If you don't want to include a polyfill, you can use an empty module like this:resolve.fallback: { "util": false } @ ./node_modules/webpack/lib/index.js 74:30-50 77:9-29 @ ./src/googlesheets.js 21:16-34 @ ./src/index.js 1:0-44 2:0-10

This particular error I searched on google as to how to resolve it and I found a solution in 'stack overflow' which I tried but no result. Following is the solution which I tried in my ones:

  1. Go to the node_modules folder

  2. Search for the react-scripts folder

  3. Inside config folder, you will see webpack.config.js file.

  4. Under the resolve part in line number 303, add this

    resolve: { fallback: { util: require.resolve("util/") }, // ... }

I'd be very grateful if anyone could help me to overcome this error.



Solution 1:[1]

I don't know if your problem has been solved or not, but I was getting the same error. For future reference, I am posting how I solved it.

I was importing like below:

import { uuid } from "uuidv4";

I was looking for a solution, then found their GitHub repo and changed importing to this:

import { v4 as uuidv4 } from 'uuid';

and this has solved my problem.

They also suggest creating a UUID like the below:

Create a UUID (ES6 module syntax)

import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ? '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'

or using CommonJS syntax:

const { v4: uuidv4 } = require('uuid');
uuidv4(); // ? '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TBA