react-native-share
react-native-share copied to clipboard
Couldnt locate ../codegenSpec/NativeRNShare.ts
Steps to reproduce
- create a react-native project with storybook and storybook-addons-react-native-web
- use react-native-share somewhere
- observe storybook breaking
Actual behavior
with the above set-up Storybook complains that the codegen spec could not be found. this is because the path to the file is wrong.
^ path is "../codegenSpec/NativeRNShare" so this will go to lib/codegenSpec/NativeRNShare but obviously that does not exist because it needs to go up 1 folder higher
I fixed this locally with patch-package:
diff --git a/node_modules/react-native-share/lib/codegenSpec/NativeRNShare.ts b/node_modules/react-native-share/lib/codegenSpec/NativeRNShare.ts
new file mode 100644
index 0000000..70f27a0
--- /dev/null
+++ b/node_modules/react-native-share/lib/codegenSpec/NativeRNShare.ts
@@ -0,0 +1,35 @@
+import type { TurboModule } from 'react-native';
+import { TurboModuleRegistry } from 'react-native';
+
+export interface Spec extends TurboModule {
+ readonly getConstants: () => {
+ FACEBOOK?: string;
+ FACEBOOKSTORIES?: string;
+ TWITTER?: string;
+ GOOGLEPLUS?: string;
+ WHATSAPP?: string;
+ INSTAGRAM?: string;
+ INSTAGRAMSTORIES?: string;
+ TELEGRAM?: string;
+ EMAIL?: string;
+ MESSENGER?: string;
+ VIBER?: string;
+ PAGESMANAGER?: string;
+ WHATSAPPBUSINESS?: string;
+ PINTEREST?: string;
+ LINKEDIN?: string;
+ SNAPCHAT?: string;
+ SHARE_BACKGROUND_IMAGE?: string;
+ SHARE_BACKGROUND_VIDEO?: string;
+ SHARE_STICKER_IMAGE?: string;
+ SHARE_BACKGROUND_AND_STICKER_IMAGE?: string;
+ SMS?: string;
+ GENERIC?: string;
+ };
+ open: (options: Object) => Promise<{ success: boolean; message: string }>;
+ shareSingle: (options: Object) => Promise<{ success: boolean; message: string }>;
+ isPackageInstalled: (packagename: string) => Promise<boolean>;
+ isBase64File: (url: string) => Promise<boolean>;
+}
+
+export default TurboModuleRegistry.getEnforcing<Spec>('RNShare');
but perhaps this is an issue with this package that needs to be solved
Environment
- React Native version: 0.71.12
- React Native platform + platform version: web
- Typescript version (if using typescript): 4.9.3
react-native-share
Version: 9.2.2
Link to repo (highly encouraged)
https://github.com/
I think this is the same problem we got in our tests. They fail right now and i don't know how to work around it.
- "react-native-share": "^9.2.3"
- "react-native": "0.71.12"
● Test suite failed to run
Cannot find module '../codegenSpec/NativeRNShare' from 'node_modules/react-native-share/lib/commonjs/index.js'
Require stack:
node_modules/react-native-share/lib/commonjs/index.js
app/helper/Image.js
app/components/stateless/atomic/CachedImage/index.js
app/components/stateless/atomic/ProfileImage/index.js
app/components/stateless/atomic/ProfileImage/test.js
13 | import { Image } from 'react-native';
14 | import imageCacheHoc from 'react-native-image-cache-hoc';
> 15 | import Share from 'react-native-share';
| ^
16 |
17 | import Api from '@constants/Api';
18 | import { THUMBNAIL_API } from '@constants/Api';
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:491:11)
at Object.require (node_modules/react-native-share/lib/commonjs/index.tsx:1:1)
at Object.require (app/helper/Image.js:15:1)
at Object.require (app/components/stateless/atomic/CachedImage/index.js:25:1)
at Object.require (app/components/stateless/atomic/ProfileImage/index.js:19:1)
at Object.require (app/components/stateless/atomic/ProfileImage/test.js:12:1)
at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
@maluramichael Friend, could you solve it?
@maluramichael Friend, could you solve it?
sadly no.
As a workaround you can use mock the could not found module @sebas21 @maluramichael
jest.mock('react-native-share', () => {
return {
NativeRNShare: () => {},
};
});
As a workaround you can use mock the could not found module @sebas21 @maluramichael
jest.mock('react-native-share', () => { return { NativeRNShare: () => {}, }; });
Thanks a lot. This helped me so much.
Happens to me when running the app (not only tests) since 9.0.0. 8.2.2 is the latest release i can use in my project.
Quick workaround with react-native-share: 10.0.2
and react-native: 0.73.1
Wrong path is being imported,
Open node_modules/react-native-share/lib/commonjs/index.js
file,
find ../codegenSpec/NativeRNShare
and replace it with ../../codegenSpec/NativeRNShare
I also needed to patch helpers/android.js
(from ../../
to ../../../
), there was import of NativeRNShare
as well. I'm on React Native 0.73.2 and react-native-share: 10.0.2
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open
:tada: This issue has been resolved in version 10.2.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket: