Warning: Ignored package due to "Package subpath './package.json' is not defined by "exports""
See original GitHub issueDescription
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® Core™ 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:
Issue Analytics
- State:
- Created 3 years ago
- Comments:13
Top GitHub Comments
A workaround seems to be that every single module on
npm
addspackage.json
to theirpkg.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 inreact-native
: https://github.com/react-native-community/cli/issues/1168I believe this should still be fixed through https://github.com/react-native-community/cli/issues/1168