Import modules using package.json name in react-native

I am developing an app on react-native and we want to use absolute path imports in our project.
For this, we are using the a workaround described here: https://github.com/facebook/react-native/issues/3099#issuecomment-221815006

The idea is that using be main package.json name we can import modules using absolute paths. This works perfectly and react-native builds without issues.

The problem is that Webstorm can't resolve these paths, thus I an losing the goToDeclaration mechanism which is very useful.

How can I configure Webstorm to be able to resolve these kinds of paths?

Thank you

0
4 comments

WebStorm provides no support for this React Native hack (not officially documented anywhere, as far as I can tell). If you miss this feature, please follow WEB-23221 for updates.

Marking a parent folder of @subdirectory specified in package.json as Resource root (note: not the subdirectory itself, but its parent dir!) should help to work out the issue - unless the @subdirectory doesn't match actual folder name

1
Avatar
Permanently deleted user

Thanks for your feedback. Marking the parent folder as a Resource root resolved my the paths correctly. I will follow the issue though for updates because I believe it should be resolved by default

0
Avatar
Permanently deleted user

What about if the subdirectory does not match the actual folder name? I'm having the same issue in PyCharm

0

No workarounds can be suggested then. Please vote for https://youtrack.jetbrains.com/issue/WEB-23221

0

Please sign in to leave a comment.