react-native-share icon indicating copy to clipboard operation
react-native-share copied to clipboard

Couldnt locate ../codegenSpec/NativeRNShare.ts

Open rpander93 opened this issue 1 year ago • 8 comments

Steps to reproduce

  1. create a react-native project with storybook and storybook-addons-react-native-web
  2. use react-native-share somewhere
  3. 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.

78230

^ 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/

rpander93 avatar Aug 07 '23 13:08 rpander93

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 avatar Aug 18 '23 11:08 maluramichael

@maluramichael Friend, could you solve it?

sebas21 avatar Sep 28 '23 22:09 sebas21

@maluramichael Friend, could you solve it?

sadly no.

maluramichael avatar Oct 03 '23 16:10 maluramichael

As a workaround you can use mock the could not found module @sebas21 @maluramichael

jest.mock('react-native-share', () => {
  return {
    NativeRNShare: () => {},
  };
});

guvenkaranfil avatar Oct 05 '23 19:10 guvenkaranfil

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.

maluramichael avatar Nov 03 '23 12:11 maluramichael

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.

dieguezz avatar Dec 15 '23 14:12 dieguezz

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

Naishadh8115 avatar Dec 27 '23 12:12 Naishadh8115

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

effektsvk avatar Feb 02 '24 15:02 effektsvk

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

github-actions[bot] avatar Apr 03 '24 01:04 github-actions[bot]

:tada: This issue has been resolved in version 10.2.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

MateusAndrade avatar May 17 '24 07:05 MateusAndrade