bjarneo / extract-domain

Extract domain name from an URL
https://www.npmjs.com/package/extract-domain
MIT License
31 stars 4 forks source link

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" #19

Closed ndlonghi closed 2 years ago

ndlonghi commented 2 years ago

I'm using this library in a React Native project, but when upgrading to react-native: 0.69.1 and trying to compile android app (npx react-native run-android) I get the following error:

error Failed to load configuration of your project.
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /my-project/node_modules/extract-domain/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at resolveNodeModuleDir (/my-project/node_modules/@react-native-community/cli-tools/build/resolveNodeModuleDir.js:24:42)
    at /my-project/node_modules/@react-native-community/cli-config/build/loadConfig.js:93:76
    at Array.reduce (<anonymous>)

I could fix it by modifying the node_modules/extract-domain/package.json and replacing the exports property with this:

"exports": {
    ".": {
      "import": "./dist/extract-domain.modern.js"
    },
    "./package.json": "./package.json"
  },

But I didn't want to create a PR with this change because I guess I'm missing some things here.

bjarneo commented 2 years ago

Hi. Interesting. I am currently on vacation, so I do not have time to look into this now, but will as soon as I am back. Thanks for the issue.

wangliang1124 commented 2 years ago

me too.

bjarneo commented 2 years ago

Should be solved in version 2.4.2. Let me know if there is any other issues.

ndlonghi commented 2 years ago

Thanks a lot @bjarneo ! Really helpful and really fast solution!

BTW: version 2.4.2 works perfect, but in latest (2.4.8) it doesn't work, I get the same error.

bjarneo commented 2 years ago

@ndlonghi No problem. Lock it to that version for now, and I will look more into it. Tried to quick fix it late night, so kind of did not make it work as expected cross environments. Reopening the issue!

wangliang1124 commented 2 years ago

With 2.4.8, it gives me a warning like this:

warn Package extract-domain has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports"

2.4.2 is ok.

ndlonghi commented 2 years ago

Hi @bjarneo, I don't think this fix is needed anymore since react-native fixed this issue in the RN CLI (https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0692). Thanks for all your support and sorry for the inconveniencies.

bjarneo commented 2 years ago

Hi @ndlonghi, great to hear! Then I do not have to look more into this.

If it happens to be anything else, please let me know :)