11

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?

through.a.haze
  • 516
  • 1
  • 6
  • 15

2 Answers2

16

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

cvekaso
  • 833
  • 1
  • 11
  • 28
2

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

evdama
  • 2,166
  • 1
  • 16
  • 17
  • did you try it with v12.16.3? – cvekaso May 11 '20 at 17:52
  • no, I did not, I'm keeping node v14.1 as downgrading doesn't seem a solution long-term – evdama May 12 '20 at 05:09
  • obviously, something is wrong with uuid 8.0.0, but I can't wait for their fix and for me downgrading Node version was the acceptable solution – through.a.haze May 12 '20 at 10:19
  • I know it's been almost a year since this issue, but I'm having it now using node: 14.16.3 uuid: 8.3.2 Did any upgrade of uuid fixed it or you just downgrade to 12.16/12.22.1? – Juan Apr 14 '21 at 20:36
  • what on earth is wrong with node/javascript when it's this hard to generate a uuid? – Mark Lindell Aug 03 '21 at 13:06
  • I am using Typescript, for some reason it used to work with `ts-eager`, then I shifted to `esbuild-runner` and I couldn't get it working without downgrading. Might help anyone. – saibbyweb Dec 25 '21 at 20:01