private-ip icon indicating copy to clipboard operation
private-ip copied to clipboard

ERR_PACKAGE_PATH_NOT_EXPORTED when using private-ip version 3.0.2

Open svrnwnsch opened this issue 1 year ago • 2 comments

I get an error when using private-ip package with version 3.0.2. which does not exist in version 3.0.1

{"type":"Error","message":"No \"exports\" main defined in XXX/node_modules/private-ip/package.json","code":"ERR_PACKAGE_PATH_NOT_EXPORTED"}

in my code I try to import package like described in the readme with import is_ip_private from 'private-ip';

svrnwnsch avatar May 24 '24 15:05 svrnwnsch

Hi @svrnwnsch! Thanks for reporting this. Could you please specify what os, node and npm versions are you using?

frenchbread avatar Jun 02 '24 11:06 frenchbread

I've encountered the same issue. MacOS, pnpm, nodejs 20, application executing with node -r esbuild-register (don't ask why, I'm not the creator). Code is in typescript.

Full stacktrace is:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in *project*/node_modules/private-ip/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:594:13)
    at resolveExports (node:internal/modules/cjs/loader:592:36)
    at Module._findPath (node:internal/modules/cjs/loader:669:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1131:27)
    at Module._resolveFilename (*project*/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:4799:36)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (*actual require*) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Jabher avatar Jun 28 '24 20:06 Jabher

I believe that this is a result of https://github.com/frenchbread/private-ip/commit/346867afe100d442f5d56233b0d93040fb682d2f - now that the exports field contains an export condition (import), it won't work with any loaders that don't include that export condition.

I haven't looked to see what export conditions esbuild-register expects.

joshkel avatar Jul 24 '25 15:07 joshkel

I no longer have this problem with the import import isIpPrivate from 'private-ip';

svrnwnsch avatar Sep 18 '25 11:09 svrnwnsch