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

pod install & react-native info fail with @react-native-community/cli-config 8.0.3 and ramda 0.28.0 installed #1650

Closed
mlazari opened this issue Jul 14, 2022 · 8 comments

Comments

@mlazari
Copy link
Contributor

mlazari commented Jul 14, 2022

Environment

mihai@Mihais-Mac-mini PackageJsonErrorRepro % npx react-native info             
error Failed to load configuration of your project.
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/ramda/package.json
    at new NodeError (node:internal/errors:370:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:335:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:560:3)
    at resolveExports (node:internal/modules/cjs/loader:476:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:516:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:913:27)
    at Function.resolve (node:internal/modules/cjs/helpers:99:19)
    at resolveNodeModuleDir (/Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/@react-native-community/cli-tools/build/resolveNodeModuleDir.js:24:42)
    at /Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/@react-native-community/cli-config/build/loadConfig.js:93:76
    at Array.reduce (<anonymous>)
info Run CLI with --verbose flag for more details.

If I remove ramda:

mihai@Mihais-Mac-mini PackageJsonErrorRepro % npx react-native info             
info Fetching system and libraries information...
System:
    OS: macOS 12.4
    CPU: (8) x64 Apple M1
    Memory: 393.95 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.5.0 - ~/.nvm/versions/node/v16.5.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.5.0/bin/yarn
    npm: 7.19.1 - ~/.nvm/versions/node/v16.5.0/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK:
      API Levels: 26, 29, 30, 31
      Build Tools: 26.0.0, 29.0.2, 30.0.2, 30.0.3, 31.0.0
      System Images: android-24 | ARM 64 v8a, android-25 | Google APIs ARM 64 v8a, android-30 | Google APIs ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8139111
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.0.0 => 18.0.0 
    react-native: 0.69.1 => 0.69.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

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 in ramda (is it required to add "./package.json" to "exports" in package.json for all npm packages that use exports?) 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 for pod install:

mihai@Mihais-Mac-mini PackageJsonErrorRepro % yarn install && cd ios && pod install
yarn install v1.22.18
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-native > react-shallow-renderer@16.14.1" has incorrect peer dependency "react@^16.0.0 || ^17.0.0".
warning "react-native > react-native-codegen > jscodeshift@0.13.1" has unmet peer dependency "@babel/preset-env@^7.1.6".
warning "@react-native-community/eslint-config > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] 🔨  Building fresh packages...

✨  Done in 3.83s.
error Failed to load configuration of your project.

[!] Invalid `Podfile` file: 859: unexpected token at 'Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/ramda/package.json

    at new NodeError (node:internal/errors:370:5)

    at throwExportsNotFound (node:internal/modules/esm/resolve:335:9)

    at packageExportsResolve (node:internal/modules/esm/resolve:560:3)

    at resolveExports (node:internal/modules/cjs/loader:476:36)

    at Function.Module._findPath (node:internal/modules/cjs/loader:516:31)

    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:913:27)

    at Function.resolve (node:internal/modules/cjs/helpers:99:19)

    at resolveNodeModuleDir (/Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/@react-native-community/cli-tools/build/resolveNodeModuleDir.js:24:42)

    at /Users/mihai/Desktop/Repos/PackageJsonErrorRepro/node_modules/@react-native-community/cli-config/build/loadConfig.js:93:76

    at Array.reduce (<anonymous>)

info Run CLI with --verbose flag for more details.
'.

 #  from /Users/mihai/Desktop/Repos/PackageJsonErrorRepro/ios/Podfile:8
 #  -------------------------------------------
 #  target 'PackageJsonErrorRepro' do
 >    config = use_native_modules!
 #  
 #  -------------------------------------------

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 even npx react-native info.

If I force "@react-native-community/cli-config": "8.0.2" via yarn "resolutions", then pod install runs fine and npx 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.2

For project using npm rather than yarn, the version can be forced to 8.0.2 via the "overrides" option:

  "overrides": {
    "@react-native-community/cli-config": "8.0.2"
  }

But there is a known issue with that: npm/cli#4232

@mlazari mlazari changed the title pod install & react-native info fail with ramda installed pod install & react-native info fail with @react-native-community/cli-config 8.0.3 and ramda 0.28.0 installed Jul 14, 2022
@jaiminbhut
Copy link

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/"
  },

@mlazari
Copy link
Contributor Author

mlazari commented Jul 16, 2022

@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?

@jaiminbhut
Copy link

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`

@mlazari
Copy link
Contributor Author

mlazari commented Jul 16, 2022

Yeah, I guess it's this commit that changed it from an warning to an error: 57b825b

@alimek
Copy link

alimek commented Jul 22, 2022

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

@matinzd
Copy link

matinzd commented Jul 22, 2022

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>)

@jinliming2
Copy link

Temporary solution:

  1. install patch-package.
  2. Create file: <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, {

@alimek
Copy link

alimek commented Jul 26, 2022

fixed with version 8.0.4 we can close it ;-)

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

No branches or pull requests

6 participants