I am trying to upgrade from react native 35 to 40. Running 'react-native-git-upgrade' in my project tells me the upgrade has been done but nothing has changed in my repository.
Output:
/usr/local/Cellar/node/7.4.0/bin/react-native-git-upgrade
git-upgrade info Check for updates
git-upgrade info Using yarn 0.19.1
git-upgrade info Read package.json files
git-upgrade info Check declared version
git-upgrade info Check matching versions
git-upgrade info Check React peer dependency
git-upgrade info Check that Git is installed
git-upgrade info Get information from NPM registry
git-upgrade info Upgrading to React Native 0.40.0, React ~15.4.0-rc.4
git-upgrade info Setup temporary working directory
git-upgrade info Configure Git environment
git-upgrade info Init Git repository
git-upgrade info Add all files to commit
git-upgrade info Commit current project sources
git-upgrade info Create a tag before updating sources
git-upgrade info Generate old version template
git-upgrade info Add updated files to commit
git-upgrade info Commit old version template
git-upgrade info Install the new version
git-upgrade info Generate new version template
git-upgrade info Add updated files to commit
warning: CRLF will be replaced by LF in android/gradlew.bat.
The file will have its original line endings in your working directory.
git-upgrade info Commit new version template
git-upgrade info Generate the patch between the 2 versions
git-upgrade info Save the patch in temp directory
git-upgrade info Reset the 2 temporary commits
git-upgrade info Apply the patch
error: patch failed: .flowconfig:1
Falling back to three-way merge...
Applied patch to '.flowconfig' with conflicts.
error: patch failed: .gitignore:22
Falling back to three-way merge...
Applied patch to '.gitignore' with conflicts.
error: android/app/src/main/java/com/appname/MainApplication.java: does not exist in index
error: cannot apply binary patch to 'android/gradle/wrapper/gradle-wrapper.jar' without full index line
Falling back to three-way merge...
error: cannot apply binary patch to 'android/gradle/wrapper/gradle-wrapper.jar' without full index line
error: android/gradle/wrapper/gradle-wrapper.jar: patch does not apply
error: patch failed: ios/appname.xcodeproj/project.pbxproj:22
Falling back to three-way merge...
Applied patch to 'ios/appname.xcodeproj/project.pbxproj' with conflicts.
error: patch failed: ios/appname.xcodeproj/xcshareddata/xcschemes/appname.xcscheme:3
Falling back to three-way merge...
Applied patch to 'ios/appname.xcodeproj/xcshareddata/xcschemes/appname.xcscheme' cleanly.
error: ios/appname/AppDelegate.m: does not exist in index
error: patch failed: ios/appname/Info.plist:45
Falling back to three-way merge...
Applied patch to 'ios/appname/Info.plist' with conflicts.
git-upgrade WARN The upgrade process succeeded but there might be conflicts to be resolved. See above for the list of files that have merge conflicts.
git-upgrade info Upgrade done
Then I look in my status
git status
On branch migration-rn40-2
Untracked files:
(use "git add <file>..." to include in what will be committed)
../../../old-logs
nothing added to commit but untracked files present (use "git add" to track)
Nothing. No conflict.
This is the ouptut after I ignored *.png in my global gitignore file (as per issue #11402). I had previously also warning related to the png files (although I never changed this part of the project since I'm only doing iOs for now).
After this script is run I get react native 40 in my node modules, but I couldn't build the project on Xcode which was complaining about the React native libraries of my project.
I guess the critical lines in the logs are the "without full index line" errors for the binaries I don't have (maybe because I never ran the android project) and the "does not exist in index" that is thrown for AppDelegate.m (I use swift instead).
I managed to get it to work by changing in cliEntry.js git apply --3way ${patchPath}
by git apply --reject ${patchPath}
which worked (I could start correctly my application afterwards) but I will have to merge manually the conflicts now.
I guess you should at least test the output code of git apply to detect a failure and print a valid error message, and maybe suggest to retry with --reset instead of --3way if the --3way failed.
@joIivier how can I apply your patch locally?
@ncuillery I have the same error from RN39 to RN41
@sibelius in cliEntry.js replace git apply --3way
by git apply --reject
, run the migration script again and merge manually the files that were rejected by git (files ending in .rej).
I think it should run git apply --reject
if git apply --3way
fails
This seems like a pretty basic thing for upgrading react native and I don't understand why more people aren't complaining about it. I've been unable to use this tool successfully and have reinstalled multiple times. Any updates here?
@joIivier where in cliEntry.js
are you seeing this? Here's mine:
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
const Config = require('./util/Config');
const assertRequiredOptions = require('./util/assertRequiredOptions');
const chalk = require('chalk');
const childProcess = require('child_process');
const commander = require('commander');
const commands = require('./commands');
const defaultConfig = require('./default.config');
const init = require('./init/init');
const minimist = require('minimist');
const path = require('path');
const pkg = require('../package.json');
import type {Command} from './commands';
import type {ConfigT} from './util/Config';
commander.version(pkg.version);
const defaultOptParser = (val) => val;
const handleError = (err) => {
console.error();
console.error(err.message || err);
console.error();
process.exit(1);
};
// Custom printHelpInformation command inspired by internal Commander.js
// one modified to suit our needs
function printHelpInformation() {
let cmdName = this._name;
if (this._alias) {
cmdName = cmdName + '|' + this._alias;
}
const sourceInformation = this.pkg
? [
` ${chalk.bold('Source:')} ${this.pkg.name}@${this.pkg.version}`,
'',
]
: [];
let output = [
'',
chalk.bold(chalk.cyan((` react-native ${cmdName} ${this.usage()}`))),
` ${this._description}`,
'',
...sourceInformation,
` ${chalk.bold('Options:')}`,
'',
this.optionHelp().replace(/^/gm, ' '),
'',
];
if (this.examples && this.examples.length > 0) {
const formattedUsage = this.examples.map(
example => ` ${example.desc}: \n ${chalk.cyan(example.cmd)}`,
).join('\n\n');
output = output.concat([
chalk.bold(' Example usage:'),
'',
formattedUsage,
]);
}
return output.concat([
'',
'',
]).join('\n');
}
function printUnknownCommand(cmdName) {
console.log([
'',
cmdName
? chalk.red(` Unrecognized command '${cmdName}'`)
: chalk.red(' You didn\'t pass any command'),
` Run ${chalk.cyan('react-native --help')} to see list of all available commands`,
'',
].join('\n'));
}
const addCommand = (command: Command, config: ConfigT) => {
const options = command.options || [];
const cmd = commander
.command(command.name, undefined, {
noHelp: !command.description,
})
.description(command.description)
.action(function runAction() {
const passedOptions = this.opts();
const argv: Array<string> = Array.from(arguments).slice(0, -1);
Promise.resolve()
.then(() => {
assertRequiredOptions(options, passedOptions);
return command.func(argv, config, passedOptions);
})
.catch(handleError);
});
cmd.helpInformation = printHelpInformation.bind(cmd);
cmd.examples = command.examples;
cmd.pkg = command.pkg;
options
.forEach(opt => cmd.option(
opt.command,
opt.description,
opt.parse || defaultOptParser,
typeof opt.default === 'function' ? opt.default(config) : opt.default,
));
// Placeholder option for --config, which is parsed before any other option,
// but needs to be here to avoid "unknown option" errors when specified
cmd.option('--config [string]', 'Path to the CLI configuration file');
};
function getCliConfig() {
// Use a lightweight option parser to look up the CLI configuration file,
// which we need to set up the parser for the other args and options
const cliArgs = minimist(process.argv.slice(2));
let cwd;
let configPath;
if (cliArgs.config != null) {
cwd = process.cwd();
configPath = cliArgs.config;
} else {
cwd = __dirname;
configPath = Config.findConfigPath(cwd);
}
return Config.get(cwd, defaultConfig, configPath);
}
function run() {
const setupEnvScript = /^win/.test(process.platform)
? 'setup_env.bat'
: 'setup_env.sh';
childProcess.execFileSync(path.join(__dirname, setupEnvScript));
const config = getCliConfig();
commands.forEach(cmd => addCommand(cmd, config));
commander.parse(process.argv);
const isValidCommand = commands.find(cmd => cmd.name.split(' ')[0] === process.argv[2]);
if (!isValidCommand) {
printUnknownCommand(process.argv[2]);
return;
}
if (!commander.args.length) {
commander.help();
}
}
module.exports = {
run: run,
init: init,
};
@joIivier @ncuillery Made a video showing my struggles lol. Any suggestions here would be greatly appreciated as our current method of upgrading, completely manual, is a total PITA.
Just tried on a coworkers computer who is in the same repo as us and got the exact same results.
@dwilt change this line: https://github.com/facebook/react-native/blob/master/react-native-git-upgrade/cliEntry.js#L331
Why my cliEntry.js doesn't the same to you i can't find the line @sibelius
I discovered that a .patch
file containing the diffs exists in $TMPDIR/react-native-git-upgrade/upgrade_0.40.0_0.42.0.patch
.
I took a look at this file, and sure enough, there's all my diffs.
So then I use git apply <path> --reject
and it all works fine.
react-native-git-upgrade
ls $TMPDIR/react-native-git-upgrade
-- you'll find your corresponding .patch
file, the name will correspond to the versions you're upgrading between.git apply <path to patch> --reject
Having this issue going from .40 to .42.3. On first try, merge conflicts registered in the proper files. But subsequent tries yielded no such luck and required the reject flag for any discernible conflict.
This issue is reproducible when the diff between the React Native project template files have changed (between your current RN version and the newest RN version) in one of the following ways:
1.3.1
to 2.2.3
, but you're already on 2.3.3
. The patch will fail since it can't find the line with the gradle version as 1.3.1
As others have identified, the upgrade process creates a patch file, then tries to apply the patch. When it tries to apply a --3way
patch, it will fail if it encounters any errors such as those above ☝️. Unfortunately, it reverses the whole patch when a 3-way patch fails to apply.
If you change the git strategy for applying the patch from --3way
to --reject
, it will allow your changes to go through, then you just have to resolve and remove the .rej
files where it had errored out. You can either do this after it fails using the patch file @ajwhite found, or change the cliEntry.js
directly as described in the PR description.
@sibelius and @whk1459086640, you should be looking for cliEntry.js
inside the react-native-git-upgrade
node_modules
directory, found where NPM (globally) installed react-native-git-upgrade.
If you change the git strategy for applying the patch from --3way to --reject, it will allow your changes to go through, then you just have to resolve and remove the .rej files where it had errored out. You can either do this after it fails using the patch file @ajwhite found, or change the cliEntry.js directly as described in the PR description.
Upgrading shouldn't require finding a hidden temp file or editing a library file. The simplest workaround would probably be adding a cli argument to react-native-git-upgrade
that will make the git command use --reject
instead of --3way
.
It seems like the patch should be agnostic as to the state of the thing needing to be upgraded, e.g. it should look to patch a version without caring about what the version number ought to have been previously. This is especially the case because both Android Studio and Xcode will upgrade native config stuff as needed, not to mention the need to manually upgrade specific lines as certain libraries might demand.
Running into this same problem on mac upgrading from react-native 0.43.3 to v0.44.3
git-upgrade info Install the new version
git-upgrade info Generate new version template
git-upgrade info Add updated files to commit
warning: CRLF will be replaced by LF in android/gradlew.bat.
The file will have its original line endings in your working directory.
git-upgrade info Commit new version template
git-upgrade info Generate the patch between the 2 versions
git-upgrade info Save the patch in temp directory
git-upgrade info Reset the 2 temporary commits
git-upgrade info Apply the patch
error: patch failed: .babelrc:1
Falling back to three-way merge...
Applied patch to '.babelrc' with conflicts.
error: patch failed: ios/pocket.xcodeproj/project.pbxproj:1196
Falling back to three-way merge...
Applied patch to 'ios/pocket.xcodeproj/project.pbxproj' with conflicts.
error: ios/pocketTests/pocketTests.m: does not exist in index
When running a git status only the gradle windows file is changed:
✗ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: android/gradlew.bat
no changes added to commit (use "git add" and/or "git commit -a")
Edit: Following the steps of https://github.com/facebook/react-native/issues/12112#issuecomment-284491701 worked for me
However i needed to apply some extra args to git apply
run:
git apply --reject --whitespace=fix $TMPDIR/react-native-git-upgrade/upgrade_0.43.3_0.44.3.patch
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
This issue still persists
Looks like this issue will be fixed (via more helpful error message) when 4fbd244b9a6b62e0efe1b4b5a7ec3de468f020f6 is released
still happening
This is fixed in 4fbd244b9a6b62e0efe1b4b5a7ec3de468f020f6
Most helpful comment
I discovered that a
.patch
file containing the diffs exists in$TMPDIR/react-native-git-upgrade/upgrade_0.40.0_0.42.0.patch
.I took a look at this file, and sure enough, there's all my diffs.
So then I use
git apply <path> --reject
and it all works fine.Working reproducible steps
react-native-git-upgrade
ls $TMPDIR/react-native-git-upgrade
-- you'll find your corresponding.patch
file, the name will correspond to the versions you're upgrading between.git apply <path to patch> --reject