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

React Native iOS unable to link @casl #523

Closed
Ogala opened this issue Jul 15, 2021 · 5 comments
Closed

React Native iOS unable to link @casl #523

Ogala opened this issue Jul 15, 2021 · 5 comments

Comments

@Ogala
Copy link

Ogala commented Jul 15, 2021

Describe the bug
TLDR: React Native iOS unable to link both @casl/ability and @casl/react due to the following warning

warn Package @casl/ability has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/emmanuelogala/Code/josplayet/node_modules/@casl/ability/package.json
warn Package @casl/react has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/emmanuelogala/Code/josplayet/node_modules/@casl/react/package.json

I recently upgraded my React and React Native to 17.0.1 and 0.64.2 and @CASL stopped working on iOS. It works on Android. During linking, I get the warning above. Due to the failure of linkage - see warning above.

When I try to use, say Can, I get a Cannot read property 'can' of undefined

To Reproduce

prerequisite: React 17.0.1, react Native 0.64.2

  1. npm install @casl/react @casl/ability
  2. Setup ability as provided in the v5 guide (https://casl.js.org/v5/en/package/casl-react)
  3. Use Can to check ability

Expected behavior
I should be able to use Can to check ability.

Interactive example (optional, but highly desirable)
provide a link to the example from http://repl.it/, https://codesandbox.io/ or similar, so we can quickly test and provide feedback. Otherwise

CASL Version

 "@casl/ability": "^5.3.1",
   "@casl/react": "^2.3.0",

Environment:

Nodejs 14-stable 
Xcode 12.5
Build version 12E5234g
@Ogala Ogala added the bug label Jul 15, 2021
@stalniy
Copy link
Owner

stalniy commented Jul 15, 2021

Did you try to add package.json to exports manually to casl’s repos, in node_modules? Just to see whether it works

@stalniy
Copy link
Owner

stalniy commented Jul 17, 2021

any updates on this?

@Ogala
Copy link
Author

Ogala commented Jul 17, 2021

any updates on this?

Yeah. I just did. It builds and links. But it still gives me the same "can not defined" error.

@Todmy
Copy link

Todmy commented Jul 29, 2021

I believe you did something wrong. I have created a simple example for the react-native app. You can check it out here.
to run it you need npm i(maybe additionally pod install in ios folder) and then npm run ios.
Everything works as expected on ARM-based arch(M1 chip), but with some extra fixes(related to expo cli, not casl). I believe on AMD it will work out of the box.

@stalniy
Copy link
Owner

stalniy commented Jul 29, 2021

Thanks @Todmy for checking it!

Close this as I don't see a reason to add package.json into exports field for some other library to be able to require it using nodejs require. React native should read this file using fs and resolve path to it without using require. Related RN issue - react-native-community/cli#1168

Otherwise, every library in npm repo that can be used with RN should add package.json into exports, what seems meaningless

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

3 participants