callstack / react-native-builder-bob

👷‍♂️ Simple set of CLIs to scaffold and build React Native libraries for different targets
https://callstack.github.io/react-native-builder-bob/
2.77k stars 183 forks source link

codegen doesn't find the library #637

Open johnf opened 1 month ago

johnf commented 1 month ago

Description

I'm updating @react-native-vector-icons/common to be in line with the latest create-react-native-libarary. I modified the codegenConfig in my package.json and the package was no longer being discovered when I run "react-native codegen"

The code that does this ignores errors in a libraries project.json. The error was

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /home/johnf/work/inodes/react-native-vector-icons/node_modules/@react-native-vector-icons/common/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:651:9)
    at resolveExports (node:internal/modules/cjs/loader:634:36)
    at Module._findPath (node:internal/modules/cjs/loader:724:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1211:27)
    at Function.resolve (node:internal/modules/helpers:190:19)
    at /home/johnf/work/inodes/react-native-vector-icons/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:241:38
    at Array.flatMap (<anonymous>)
    at findExternalLibraries (/home/johnf/work/inodes/react-native-vector-icons/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:239:36)
    at findCodegenEnabledLibraries (/home/johnf/work/inodes/react-native-vector-icons/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:538:10) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Packages

Selected options

I fixed this by adding the following to package.json

diff --git a/packages/common/package.json b/packages/common/package.json
index fc67253..20ec4aa 100644
--- a/packages/common/package.json
+++ b/packages/common/package.json
@@ -6,6 +6,7 @@
   "main": "./lib/commonjs/index.js",
   "module": "./lib/module/index.js",
   "exports": {
+    "./package.json": "./package.json",
     ".": {
       "import": {
         "types": "./lib/typescript/module/src/index.d.ts",

Link to repro

https://github.com/oblador/react-native-vector-icons/tree/monorepo in about 20 mins haven't commited yet you'll need to undo the fix in package.json

Environment

System: OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat) CPU: (16) x64 AMD Ryzen 7 7840U w/ Radeon 780M Graphics Memory: 15.90 GB / 30.66 GB Shell: version: 5.2.21 path: /bin/bash Binaries: Node: version: 20.17.0 path: ~/.nvm/versions/node/v20.17.0/bin/node Yarn: version: 4.2.2 path: ~/.nvm/versions/node/v20.17.0/bin/yarn npm: version: 10.8.2 path: ~/.nvm/versions/node/v20.17.0/bin/npm Watchman: Not Found SDKs: Android SDK: API Levels:

atlj commented 1 day ago

Hey @johnf thank you so much for creating an issue about this. This helped us find a bigger problem in CRNL and bob. You can find more details in #658.