Warning: Ignored package due to "Package subpath './package.json' is not defined by "exports""
omonk opened this issue · 15 comments
Description
I'm using i18next for translations, recently a backend connector for getting translation files was deprecated and replaced with a new package, i18next-http-backend
.
Initially firing up the app metro throws as it is unable to resolve getFetch.cjs
, adding the follow to metro.config.js removes this error:
const { getDefaultValues } = require("metro-config/src/defaults");
const {
resolver: { sourceExts }
} = getDefaultValues();
///
module.exports = {
resolver: {
extraNodeModules,
sourceExts: [...sourceExts, "cjs"]
},
}
Next, when firing up the app with react-native start
with the new package the console shows a warning:
warn Package i18next-http-backend has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /path/to/app/node_modules/i18next-http-backend/package.json
Looking closer into the package.json I can see it's using the latest module resolution for cjs and esm environments.
However, loading up the app on xcode simulator, the relevant requests are performed correctly and the right translation files are downloaded without any issues.
Question is, where is the warning coming from and should we be concerned?
React Native version:
System:
OS: macOS 10.15.2
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 299.27 MB / 16.00 GB
Shell: 3.0.2 - /usr/local/bin/fish
Binaries:
Node: 13.13.0 - /usr/local/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 27, 28
Build Tools: 28.0.3, 29.0.2, 30.0.0
System Images: android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.4/11E146 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
- In any react-native project
> yarn add i18next-http-backend
- Run
> react-native start
, N.B. you wont need to import the package from anywhere, I assume this warning is produced from some sort of analysis of root package.json dependencies. - See warning as first output from react-native scripts
warn Package i18next-http-backend has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /path/to/app/node_modules/i18next-http-backend/package.json
Expected Results
No warning is shown in the console
Snack, code example, screenshot, or link to a repository:
Moving to metro repo
Hey @alfonsocj, I've not managed to solve it, it does seems to just work but not super comfortable with it. Do you have the same thing?
Right. I have the exact same problem.
I got sidetracked and haven't opened an issue in metro, I've found some other issues opened on the metro repo but nothing seems to of come from it:
Initial discussion regarding module exports: ai/nanoevents#44
Metro issue thats not had any comments: facebook/metro#535
Does your import with the warning make it into the bundle?
I do not see the warning after modifying metro.config.json. Everything seems to work fine.
Out of curiosity which package is it that you're seeing this happen with? And which RN version?
Reverting node to LTS fixed this for me.
Should be fixed with i18next/i18next-http-backend@1d8da79#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R8 in v1.0.10
A workaround seems to be that every single module on npm
adds package.json
to their pkg.exports
field.
However, especially since other bundlers like webpack and rollup, which also pull configuration from package.json
, don't seem to suffer this issue, it might make more sense to fix this in react-native
: react-native-community/cli#1168
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
I believe this should still be fixed through react-native-community/cli#1168
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.