Help Codegen to find library's package.json after failure of importing library's package.json due to missing of ./package.json subpath (#53195)#53220
Closed
cipolleschi wants to merge 1 commit into
Conversation
…g library's package.json due to missing of `./package.json` subpath (facebook#53195) Summary: This is fix for some React Native libraries can't be found by Codegen, and will make the libraries unusable in new architecture (Turbo Modules) Internally in the Codegen script, it will try to import library's package.json file with the `require.resolve`, but for some React Native libraries will throw an error with `ERR_PACKAGE_PATH_NOT_EXPORTED` code due to using the `exports` field in their package.json file while not exposing the package.json file itself. As an example ```json { "exports": { ".": { "import": { "types": "./lib/typescript/module/index.d.ts", "default": "./lib/module/index.js" }, "require": { "types": "./lib/typescript/commonjs/index.d.ts", "default": "./lib/commonjs/index.js" } }, "./package.json": "./package.json" <-- here some libraries missed this }, "codegenConfig": {} } ``` Personally feel weird that library author has to expose their package.json only for the sake of Codegen and i believe library author shouldn't, even the library consumer don't need it. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [GENERAL] [FIXED] - Help Codegen find library's package.json if some libraries using `exports` field in their package.json file and the `./package.json` subpath is not explicitly defined bypass-github-export-checks Test Plan: `require.resolve('library/package.json')` [here](https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js#L203) will throw an error with `ERR_PACKAGE_PATH_NOT_EXPORTED` code by Node.js. So if it does, help Codegen retry to find closest library's package.json with [`require.main.paths`](https://nodejs.org/api/modules.html#requiremain) search paths You can init new app React Native CLI app with my sample react native library here [`ping-react-native`](https://github.com/RakaDoank/ping-react-native) v1.2.2. Due to missing of the `package.json` subpath, before this change, it's autolinked but unusable due to missing of the spec header file. After this change, it works normally. Rollback Plan: Reviewed By: cortinico Differential Revision: D80080243 Pulled By: cipolleschi
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D80080243 |
Collaborator
|
This pull request was successfully merged by @RakaDoank in 739dfd2 When will my fix make it into a release? | How to file a pick request? |
Contributor
|
@cipolleschi merged this pull request in 739dfd2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This is fix for some React Native libraries can't be found by Codegen, and will make the libraries unusable in new architecture (Turbo Modules)
Internally in the Codegen script, it will try to import library's package.json file with the
require.resolve, but for some React Native libraries will throw an error withERR_PACKAGE_PATH_NOT_EXPORTEDcode due to using theexportsfield in their package.json file while not exposing the package.json file itself. As an example{ "exports": { ".": { "import": { "types": "./lib/typescript/module/index.d.ts", "default": "./lib/module/index.js" }, "require": { "types": "./lib/typescript/commonjs/index.d.ts", "default": "./lib/commonjs/index.js" } }, "./package.json": "./package.json" <-- here some libraries missed this }, "codegenConfig": {} }Personally feel weird that library author has to expose their package.json only for the sake of Codegen and i believe library author shouldn't, even the library consumer don't need it.
Changelog:
[GENERAL] [FIXED] - Help Codegen find library's package.json if some libraries using
exportsfield in their package.json file and the./package.jsonsubpath is not explicitly definedbypass-github-export-checks
Test Plan:
require.resolve('library/package.json')here will throw an error withERR_PACKAGE_PATH_NOT_EXPORTEDcode by Node.js. So if it does, help Codegen retry to find closest library's package.json withrequire.main.pathssearch pathsYou can init new app React Native CLI app with my sample react native library here
ping-react-nativev1.2.2.Due to missing of the
package.jsonsubpath, before this change, it's autolinked but unusable due to missing of the spec header file. After this change, it works normally.Rollback Plan:
Reviewed By: cortinico
Differential Revision: D80080243
Pulled By: cipolleschi