100mslive / 100ms-react-native

React Native Live Streaming, Video Conferencing SDK & Sample App
https://www.100ms.live/
MIT License
80 stars 31 forks source link

Unable to resolve version from package.json #910

Closed joelso closed 1 year ago

joelso commented 1 year ago

Got this error when trying to start the app after installing dependencies. Seems like it fails to resolve relative path to package.json.

If I manually alter the path to package.json to require('../../../package.json'); it works fine.

error: Error: Unable to resolve module ../../package.json from /Users/joel/projects/repeak/repeak-app/node_modules/@100mslive/react-native-hms/lib/commonjs/classes/HMSSDK.js: 

None of these files exist:
  * node_modules/@100mslive/react-native-hms/lib/package.json(.native|.ios.jsx|.native.jsx|.jsx|.ios.js|.native.js|.js|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.cjs|.native.cjs|.cjs|.ios.json|.native.json|.json)
  * node_modules/@100mslive/react-native-hms/lib/package.json/index(.native|.ios.jsx|.native.jsx|.jsx|.ios.js|.native.js|.js|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.cjs|.native.cjs|.cjs|.ios.json|.native.json|.json)
  1171 |     const {
  1172 |       version
> 1173 |     } = require('../../package.json');
       |                  ^
  1174 |     const {
  1175 |       major,
  1176 |       minor,
    at ModuleResolver.resolveDependency (/Users/joel/projects/repeak/repeak-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:136:15)
    at DependencyGraph.resolveDependency (/Users/joel/projects/repeak/repeak-app/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
    at Object.resolve (/Users/joel/projects/repeak/repeak-app/node_modules/metro/src/lib/transformHelpers.js:129:24)
    at resolve (/Users/joel/projects/repeak/repeak-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
    at /Users/joel/projects/repeak/repeak-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (/Users/joel/projects/repeak/repeak-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
    at processModule (/Users/joel/projects/repeak/repeak-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:140:31)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

Here is the diff that solved my problem:

diff --git a/node_modules/@100mslive/react-native-hms/lib/commonjs/classes/HMSSDK.js b/node_modules/@100mslive/react-native-hms/lib/commonjs/classes/HMSSDK.js
index 9fb7348..01b9f49 100644
--- a/node_modules/@100mslive/react-native-hms/lib/commonjs/classes/HMSSDK.js
+++ b/node_modules/@100mslive/react-native-hms/lib/commonjs/classes/HMSSDK.js
@@ -1170,7 +1170,7 @@ class HMSSDK {
   static async build(params) {
     const {
       version
-    } = require('../../package.json');
+    } = require('../../../package.json');
     const {
       major,
       minor,
stanwolverine commented 1 year ago

Hey @joelso Thanks for reporting this error. Yes, that path provided to require method call is incorrect. We are working on a fix. In the meanwhile you can work with your fix.

Can you tell us when are you getting this error? for example:

  1. when you are running your app with @100mslive/react-native-hms package, or
  2. when you are running tests in your app with node from cli or any other case

We are not encountering this error with normal usage of @100mslive/react-native-hms package with import statements.

ygit commented 1 year ago

hey @joelso

Can you tell us when are you getting this error? For example:

  1. When you are running your app with @100mslive/react-native-hms package? Or
  2. When you are running tests in your app with node from cli or any other case?
ygit commented 1 year ago

hey @joelso were you able to check this?

ygit commented 1 year ago

hey @joelso Were you able to check out this issue?

ygit commented 1 year ago

hey @joelso Hope that you were able to resolve this issue. You can join our Discord for any further assistance: https://100ms.live/discord