Closed mlazari closed 2 years ago
You need to change node_modules/ramda/package.json file export section like
"exports": {
"./package.json": "./package.json", //add this
".": {
"require": "./src/index.js",
"import": "./es/index.js",
"default": "./src/index.js"
},
"./es/": "./es/",
"./src/": "./src/",
"./dist/": "./dist/"
},
@jaiminbhut I know that change fixes it, but I wasn't sure if I should open a issue / PR in ramda
to do that change or it is a bug in @react-native-community/cli-config
that should be fixed. Is every package required to export package.json
in order to work with react-native
?
I'm not sure, but I think that there is a problem with the ramda
package because I started experiencing it with React Native version 0.69.1 before that, React Native was only sending warning like
Package ramda has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in `node_modules/ramda/package.json`
Yeah, I guess it's this commit that changed it from an warning to an error: https://github.com/react-native-community/cli/commit/57b825b37cb11e85bea91ca7ae10633158caaad9
same issues is with d3-array package :
Invalid `Podfile` file: 859: unexpected token at 'Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in XXX/node_modules/d3-array/package.json
same issue with fast-check
and lint-staged
. Most third parties are broken.
[!] Invalid `Podfile` file: 859: unexpected token at 'Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/matin/w/dietdoctor/rnapp/node_modules/lint-staged/package.json
at new NodeError (node:internal/errors:372:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
at packageExportsResolve (node:internal/modules/esm/resolve:753: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 (/Users/matin/w/dietdoctor/rnapp/node_modules/@react-native-community/cli-tools/build/resolveNodeModuleDir.js:24:42)
at /Users/matin/w/dietdoctor/rnapp/node_modules/@react-native-community/cli-config/build/loadConfig.js:93:76
at Array.reduce (<anonymous>)
Temporary solution:
patch-package
.<project_root>/patches/@react-native-community+cli-config+8.0.3.patch
:diff --git a/node_modules/@react-native-community/cli-config/build/loadConfig.js b/node_modules/@react-native-community/cli-config/build/loadConfig.js
index fcf5068..8942788 100644
--- a/node_modules/@react-native-community/cli-config/build/loadConfig.js
+++ b/node_modules/@react-native-community/cli-config/build/loadConfig.js
@@ -90,8 +90,19 @@ function loadConfig(projectRoot = (0, _cliTools().findProjectRoot)()) {
};
const finalConfig = Array.from(new Set([...Object.keys(userConfig.dependencies), ...(0, _findDependencies.default)(projectRoot)])).reduce((acc, dependencyName) => {
const localDependencyRoot = userConfig.dependencies[dependencyName] && userConfig.dependencies[dependencyName].root;
- let root = localDependencyRoot || (0, _cliTools().resolveNodeModuleDir)(projectRoot, dependencyName);
- let config = (0, _readConfigFromDisk.readDependencyConfigFromDisk)(root, dependencyName);
+ let root;
+ let config;
+ try {
+ root = localDependencyRoot || (0, _cliTools().resolveNodeModuleDir)(projectRoot, dependencyName);
+ config = (0, _readConfigFromDisk.readDependencyConfigFromDisk)(root, dependencyName);
+ } catch (error) {
+ _cliTools().logger.warn((0, _cliTools().inlineString)(`
+ Package ${dependencyName} has been ignored because it contains invalid configuration.
+
+ Reason: ${error.message}`));
+
+ return acc;
+ }
const isPlatform = Object.keys(config.platforms).length > 0;
return (0, _assign.default)({}, acc, {
dependencies: (0, _assign.default)({}, acc.dependencies, {
fixed with version 8.0.4
we can close it ;-)
Environment
If I remove
ramda
:Description
pod install
throws an error with"@react-native-community/cli-config": "8.0.3"
and"ramda": "0.28.0"
installed. I am not sure if this is something that should be fixed inramda
(is it required to add"./package.json"
to"exports"
inpackage.json
for all npm packages that useexports
?) or in this project. The error does not happen with"@react-native-community/cli-config": "8.0.2"
.The error for
npx react-native info
can be seen above, at the beginning of this description. The error forpod install
:Reproducible Demo
New React Native 0.69.1 project with ramda 0.28.0 installed: https://github.com/mlazari/PackageJsonErrorRepro/tree/main To reproduce run
yarn install && cd ios && pod install
, or evennpx react-native info
.If I force
"@react-native-community/cli-config": "8.0.2"
via yarn "resolutions", thenpod install
runs fine andnpx react-native info
just shows a warning for ramda (warn Package ramda has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/ramda/package.json
): https://github.com/mlazari/PackageJsonErrorRepro/tree/cli-config-8.0.2For project using npm rather than yarn, the version can be forced to
8.0.2
via the "overrides" option:But there is a known issue with that: https://github.com/npm/cli/issues/4232