I got this error when using uuidv4.
Failure: Package subpath './v4' is not defined by "exports" in C:\Users\mycomp\Desktop\Programming\Javascript\Serverless\Serverless Framework\node_modules\uuid\package.json
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports" in C:\Users\mycomp\Desktop\Programming\Javascript\Serverless\Serverless Framework\node_modules\uuid\package.json
I already installed uuid and require it in my code
const uuidv4 = require('uuid/v4');
Here's the package.json
"dependencies": {
"aws-sdk": "^2.702.0",
"moment": "^2.27.0",
"serverless-offline": "^6.4.0",
"underscore": "^1.10.2",
"uuid": "^8.1.0"
}
ECMAScript Module syntax:
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
CommonJS syntax:
const { v4: uuidv4 } = require('uuid');
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
Another option
const uuid = require('uuid');
uuid.v4(); // "c438f870-f2b7-4b2c-a1c3-83bd88bb1d79"
We had the same error with v1 uuid module (v8.3.2).
Solved this, adding following entry to exports
section of installed uuid package.json
(inside your node_modules
):
"./v1": "./dist/v1.js"
Full export section of my projects' node_modules/uuid/package.json
:
"exports": {
".": {
"node": {
"module": "./dist/esm-node/index.js",
"require": "./dist/index.js",
"import": "./wrapper.mjs"
},
"default": "./dist/esm-browser/index.js"
},
"./package.json": "./package.json",
"./v1": "./dist/v1.js"
},
The problem remaining i now need to keep this modification across dist installs... :/
This could be fixed with a patch on uuid source itself?
EDIT: Didn't require the module in our own source. It is a dependency of jest (via some jest reporting sub-pkg).
EDIT: Alternatively, rolling back to uuid dep to v7.0.3
may fix this issue too, see comment below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With