-
Notifications
You must be signed in to change notification settings - Fork 903
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" #1168
Package subpath './package.json' is not defined by "exports" #1168
Comments
From nodejs docs:
So |
Just to clarify: The problem in react-native cli is not the loading of the cli/packages/cli/src/tools/config/readConfigFromDisk.ts Lines 19 to 25 in 5819a17
which uses The problem is about resolving the path to the module's cli/packages/cli/src/tools/config/resolveNodeModuleDir.ts Lines 6 to 15 in 5819a17
|
Is there a reasonable workaround without needing to make a PR to every project with this issue? |
fix pending, assumed temporary see react-native-community/cli#1168
When using Zod in a react-native app, we see the following warning when running the bundler: ``` warn Package zod has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in <path>/node_modules/zod/package.json ``` The problem is described in react-native-community/cli#1168 and that is where it should be properly fixed. In the meantime (that issue has been open for some time), the warning can be fixed in affected packages by adding an export for `package.json`.
|
When sub-modules contain multiple exports in react-native projects, the root package.json is required Resolves: react-native-community/cli#1168
Please don't open issues/PRs on open source projects about this. It is not expected that packages export their package.json file. This is a problem React Native needs to fix, not every single package out there. |
React Native community cli parses package.json to determine the local filesystem path of imported modules. See react-native-community/cli#1168
@react-native-community/cli (used by expo and I *think* react native), parses package.json to determine package paths. This is necessary to build react native projects. See react-native-community/cli#1168 for more details.
@react-native-community/cli (used by expo and I think react native), parses package.json to determine package paths. This is necessary to build react native projects. See react-native-community/cli#1168 for more details.
When using Zod in a react-native app, we see the following warning when running the bundler: ``` warn Package zod has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in <path>/node_modules/zod/package.json ``` The problem is described in react-native-community/cli#1168 and that is where it should be properly fixed. In the meantime (that issue has been open for some time), the warning can be fixed in affected packages by adding an export for `package.json`.
Environment
Description
When running
react-native
under Node.js 14.x on a project that uses npm modules which specify the newexports
field inpackage.json
,react-native
will print the following warning (in this example theuuid
package is used):The same issue has been reported in other places:
i18next-http-backend
: Warning: Ignored package due to "Package subpath './package.json' is not defined by "exports"" facebook/react-native#28710 for (workaround: i18next/i18next-http-backend@1d8da79#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R8)i18next-locize-backend
: https://github.com/locize/i18next-locize-backend/pull/326/filesnanoevents
: Importing error in React Native starting from nanoevents 3.0 version ai/nanoevents#44uuid
: package.json is not defined by "exports" uuidjs/uuid#444 (comment)The reason is that, starting in Node.js 14.x, as soon as an npm module defines the
exports
field inpackage.json
, only the files listed there are exported. Ifpackage.json
is not included in that list, it's no longer possible to do things likerequire.resolve('uuid/package.json');
.The problematic piece of code is:
cli/packages/cli/src/tools/config/resolveNodeModuleDir.ts
Lines 11 to 13 in 5819a17
For a package like
uuid
which does not contain react-native specific configuration inpackage.json
this is not a problem, but for modules that do contain such config inpackage.json
they will be forced to addpackage.json
to theirexports
field.An alternative would be to not rely on
require.resolve
and instead use https://github.com/browserify/resolveAs far as I know this is how rollup.js solves this issue, see rollup/plugins#208 (comment)
What is the maintainers take on this? Do you think that every single module on npm that starts making use of the
exports
field should includepackage.json
in theexports
? Or could this be fixed in react-native?Reproducible Demo
npm i [email protected]
node
repl:The text was updated successfully, but these errors were encountered: