这是indexloc提供的服务,不要输入任何密码
Skip to content

React Native binary gives wrong version number #175

@skellock

Description

@skellock

Problem

Solidarity is reporting that I have the wrong version of React Native installed.

✖ react-native: you have '21', but the project requires '^2.0.1'

Config

In my .solidarity file I have this:

    "React Native": [
      {
        "rule": "cli",
        "binary": "react-native",
        "semver": "^2.0.1",
        "platform": "darwin"
      }
    ],

System Settings

System
  platform           darwin
  arch               x64
  cpu                8 cores                               Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz

JavaScript
  node               9.5.0        /usr/local/bin/node
  npm                5.6.0        /usr/local/bin/npm
  yarn               1.3.2        /usr/local/bin/yarn

React Native
  react-native-cli   2.0.1
  app rn version     0.53.0

Symptoms

From my shell, if I type react-native --version I get this:

image

If I type: ./node_modules/.bin/react-native --version I get this:

image

Path Hijacking

When you exec a command with Node.JS, it prepends several node binary paths in front of anything that is defined in your shell.

That means ./node_modules/.bin/react-native wins over $(which react-native).

Which means our command output gets us:

Scanning folders for symlinks in /Users/steve/src/ir/clients/lanetix/node_modules (21ms)
0.53.0

Instead of

react-native-cli: 2.0.1
react-native: 0.53.0

Which means your regex is picking up the (21ms) part instead of the 0.53.0 part.

Giving you version 21 installed.

Even If It Did Work...

Here's the fun part.

Let's say you put a "line": 2 in your solidarity rule.

Now you get:

✖ react-native: you have '0.53.0', but the project requires '^2.0.1'

It's reporting the react-native dependency and not the react-native-cli.

Effectively, the react-native-cli becomes invisible unless you start mucking about with the env.PATH that exec uses.

react-native-cli vs react-native

react-native-cli is only required to create a project. If you are using .solidarity, you already have your project created... so this rule is kinda redundant if you already have a rule that checks for the presence of the node_modules directory.

I'm just going to delete the rule in my projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions