React-native-branch-deep-linking-attribution: Doesn't work with NPM instead of yarn

Created on 19 Apr 2019  路  8Comments  路  Source: BranchMetrics/react-native-branch-deep-linking-attribution

This SDK does not work correctly when installed via NPM instead of yarn. There are two failures:

  • The postlink hook (when using react-native link) requires npmlog and xcode, both of which fail to load.
  • An import branch from 'react-native-branch' fails in JavaScript.

For the time being, npm add is being removed from the docs with a note. If yarn is installed, the RN toolchain will use yarn. Since yarn and NPM don't coexist well in the same project, it's likely most apps are using yarn. This is mainly an issue for anyone who doesn't want to use yarn.

Most helpful comment

Confirmed this works. Closing this issue.

All 8 comments

This is rather annoying. Any chance to get this fixed?

any update here? This is really annoying as our entire project uses npm.

Any update on a fix? Our project uses on npm and we hope to keep using npm in the future as well.

@bramski @taschik @YachaT I have no immediate update. I used to maintain a package-lock.json for every example, but I never tested. No one ever reported the problem. Another Branch engineer found it during testing. I suspect it was broken for a long time, though I know a long time ago I used npm successfully. I'm not sure, but my impression was the only way you could run into this is if you simply don't install yarn, since the RN toolchain tends to use yarn if it's present. But of course, not installing yarn is also an option. Yarn and NPM no longer seem to be compatible in the same project, so if you have yarn installed, it seems like you have little choice but to use yarn install instead of npm install. Since this had not been reported as a problem, we had the suspicion this didn't really affect anyone.

Now that we know that this does affect some Branch Partners, I'll make it a priority to determine how to fix this. One problem was in our postlink/postunlink hooks, which are dead as of 4.x, though still present in 3.x (for RN < 0.60). The big problem is that the import or require of react-native-branch just fails, and right now I have absolutely no idea why. If anyone has any insight into what's wrong, please feel free to share it. I'm sure I'll find the solution on my own, but I don't have an immediate estimate.

This currently always fails for me, and npm i fails with any app I try using RN 0.59 or 0.60.

react-native init TestApp
cd TestApp
rm -fr node_modules
npm i

And if I completely uninstall yarn and try react-native init, I get the same error from npm i during react-native init.

[jdee@Jimmy-Dees-MacBookPro sandbox]$ react-native init TestApp
This will walk you through creating a new React Native project in /Users/jdee/sandbox/TestApp
Installing react-native...
Consider installing yarn to make this faster: https://yarnpkg.com
npm ERR! Unexpected end of JSON input while parsing near '...L2gH8DvDilRY8M+ijWBHX'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jdee/.npm/_logs/2019-07-25T21_54_58_655Z-debug.log
{ Error: Command failed: npm install --save --save-exact react-native
    at checkExecSyncError (child_process.js:616:11)
    at execSync (child_process.js:653:13)
    at run (/Users/jdee/.nvm/versions/node/v10.15.0/lib/node_modules/react-native-cli/index.js:294:5)
    at createProject (/Users/jdee/.nvm/versions/node/v10.15.0/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/Users/jdee/.nvm/versions/node/v10.15.0/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/Users/jdee/.nvm/versions/node/v10.15.0/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 59002,
  stdout: null,
  stderr: null }
Command `npm install --save --save-exact react-native` failed.

2019-07-25T21_54_58_655Z-debug.log

I currently have no idea how it's possible to use npm with RN. I'll keep looking, but any feedback on this issue is welcome.

System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 4.61 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.10.2 - ~/.nvm/versions/node/v10.15.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
    Android SDK:
      API Levels: 21, 22, 23, 24, 25, 26, 27, 28
      Build Tools: 23.0.1, 25.0.0, 25.0.2, 27.0.3, 28.0.3
      System Images: android-23 | Google APIs Intel x86 Atom, android-24 | Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.3 => 0.60.3 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.3.0-beta.1

@bramski @taschik @YachaT It appears this issue may no longer be valid. tl;dr: Everything works with NPM.

My issue above was resolved with npm cache clean --force. I've verified the following with NPM instead of yarn:

  • react-native init
  • webview_example in the master branch with RN 0.60.3, react-native-branch 4.x
  • webview_tutorial in the master branch with RN 0.60.3, react-native-branch 4.x
  • webview_example in the maintenance-3.x branch with RN 0.59.6, react-native-branch 3.x
  • webview_tutorial in the maintenance-3.x branch with RN 0.59.6, react-native-branch 3.x

In the case of webview_example, I had to change file:../.. in package.json to either ^3.1.1 or ^4.1.0. With webview_tutorial, npm i --save react-native-branch@^3.1.1 or npm i --save react-native-branch instead of file:../... Using the local repo in each case caused some errors.

We confirmed this problem in the past. Maybe it was related to an older RN version. I'd like to get at least one confirmation before closing the issue. If anyone has problems, please provide the output of react-native info and the version of react-native-branch that you're using.

Confirmed this works. Closing this issue.

I still have the issue.

"react-native": "0.60.4"
"react-native-branch": "3.1.1"
npm 6.9.0
$ react-native link react-native-branch

info Linking "react-native-branch" iOS dependency
info iOS module "react-native-branch" has been successfully linked
info Linking "react-native-branch" Android dependency
info Android module "react-native-branch" has been successfully linked
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/user/Documents/dev/MyApp/node_modules/react-native-branch/scripts/androidUtil.js:2:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
error Linking "react-native-branch" failed. Run CLI with --verbose flag for more details.
Error: Command failed: node ./node_modules/react-native-branch/scripts/addBranchConfig.js
    at makeError (/Users/user/Documents/dev/MyApp/node_modules/react-native/node_modules/execa/index.js:174:9)
    at Promise.all.then.arr (/Users/user/Documents/dev/MyApp/node_modules/react-native/node_modules/execa/index.js:278:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)

branch.json

{
    "debugMode": true,
    "liveKey": "MY_LIVE_KEY",
    "testKey": "MY_TEST_KEY",
    "useTestInstance": true,
    "delayInitToCheckForSearchAds": true,
    "appleSearchAdsDebugMode": true
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pyankoff picture pyankoff  路  5Comments

stefanlenoach picture stefanlenoach  路  8Comments

SurajMDurgad picture SurajMDurgad  路  4Comments

jandrell-formoso picture jandrell-formoso  路  4Comments

jayporta picture jayporta  路  7Comments