Node version is :
uuid version is : 9.0.1
When I`m running the node server encountering the following error :
How am I using the uuid lib is :
Importing it as :
const uuid = require('uuid/v4');
utilizing it as:
id: uuid()
By keeping in mind about version compatibility of node & uuid.
We are trying to import the specific version of the uuid. This error is bcz of the way uuidv4(version 4) is being imported & used.
The uuid package updated its structure from version 8.0.0 & the way to import specific UUID versions like v4 has been modified.
In order to solve this error, follow the steps :
const { v4: uuidv4 } = require('uuid');
const { v4: uuidv4 } = require('uuid'); // this is how we imported it.
const uniqueId = uuidv4();
console.log(uniqueId);
Doing the above 2 step will solve this error.
There is a bit of difference in how we use it with ES6 module & CommonJS
For in-depth usage & explanation, please refer to the documentation here.