Getting "Error: Package exports for 'D:\test\node_modules\uuid' do not define a '.' subpath" all the time when I require it.
OS - Windows 10 Pro
Node version - v13.1.0
NPM version - 6.14.4
I created a project from scratch and run npm init -y
to create initial package.json
Then I installed uuid by running npm install uuid
and created index.js with nothing but only
const { v4: uuidv4 } = require('uuid');
uuidv4();
from their example
But whenever I try to run this code node ./index.js
I always get this error:
internal/modules/cjs/loader.js:488
throw e;
^
Error: Package exports for 'D:\test\node_modules\uuid' do not define a '.' subpath
at applyExports (internal/modules/cjs/loader.js:485:15)
at resolveExports (internal/modules/cjs/loader.js:508:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
at Function.Module._load (internal/modules/cjs/loader.js:785:27)
at Module.require (internal/modules/cjs/loader.js:956:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (D:\test\index.js:1:24)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10) {
code: 'MODULE_NOT_FOUND'
}
What am I doing wrong?
The uuid, or universally unique identifier, npm package is a secure way to generate cryptographically strong unique identifiers with Node. js that doesn't require a large amount of code.
Node.js NPM uuid. Last Updated : 26 Aug, 2020. NPM (Node Package Manager) is a package manager of Node.js packages. There is an NPM package called ‘shortid’ used to create short non-sequential url-friendly unique ids. Unique ids are created by Cryptographically-strong random values that’s why it is very secure.
To solve the error "Cannot find module 'uuid'", make sure to install the uuid package by opening your terminal in your project's root directory and running the following command: npm i uuid. If you use TypeScript, install the typings by running npm i -D @types/uuid.
Node.js NPM uuid. NPM (Node Package Manager) is a package manager of Node.js packages. There is an NPM package called ‘shortid’ used to create short non-sequential url-friendly unique ids. Unique ids are created by Cryptographically-strong random values that’s why it is very secure.
You SHOULD commit it to the source control like Git, etc. This is a new lock file feature from NPM@5 and contains a snapshot of the current dependency tree and allows for reproducible builds between machines. You might be thinking that the same can already be achieved with npm shrinkwrap and its npm-shrinkwrap.json.
Have you been able to resolve the issue?
I'm getting the same result but the only change I made is go from uuid v7.0.3 to v8.0.0. node didn't change, it's v14.1.0 which works with uuid v7.0.3.
I created an issue for it https://github.com/uuidjs/uuid/issues/444
I know that Nodejs version v13 had some issues with this. I tried with v12.16.3 and it's working. Either use latest v14.2.0 or official LTS v12.16.3
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