Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package subpath './package.json' is not defined by "exports" in /.../node_modules/yargs/package.json #1817

Closed
toverux opened this issue Dec 1, 2020 · 6 comments

Comments

@toverux
Copy link
Contributor

@toverux toverux commented Dec 1, 2020

For an unknown reason, my build fails at some point with the following error:

Package subpath './package.json' is not defined by "exports" in /.../node_modules/yargs/package.json

There is no more context on why the package.json from yargs is required.

However, adding this key in the exports of yargs' package.json works :

"exports": {
  "./package.json": "./package.json"
}

Since yargs decided to add explicit exports, it would be a nice to let external tools read yargs' package description.

@bcoe
Copy link
Member

@bcoe bcoe commented Dec 1, 2020

@toverux could you provide an example of where this is failing?

@mingtsay
Copy link

@mingtsay mingtsay commented Dec 2, 2020

I also have this issue when I run react-native link in my react native project.

@toverux
Copy link
Contributor Author

@toverux toverux commented Dec 2, 2020

In my case, this happens with NativeScript. Maybe it's scanning node_modules for plugins? (not familiar enough with it yet).
I already checked that yargs isn't accidentally bundled with my client code as this happens during compilation, but it's ok, so I probably have no more leverage here.
Like I said, the error happens without any more context. I will try to provide more context tomorrow if needed and if I can (I guess there is a way to debug require stacks), but the issue seems clear though, any tool requireing the package.json of yargs would fail, as exports acts like a whitelist, only files listed in it are now reachable through the Node resolution algorithm.

Like in CommonJS, module files within packages can be accessed by appending a path to the package name unless the package’s package.json contains an "exports" field, in which case files within packages can only be accessed via the paths defined in "exports".

https://nodejs.org/api/esm.html

See also : react-native-community/cli#1168 (comment)

@bcoe
Copy link
Member

@bcoe bcoe commented Dec 2, 2020

@toverux if you've confirmed adding the additional export works, mind submitting a patch?

@toverux
Copy link
Contributor Author

@toverux toverux commented Dec 3, 2020

Will do!

@bcoe
Copy link
Member

@bcoe bcoe commented Dec 5, 2020

give yargs@16.2.0 a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants