Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native 0.73 npx rnn-link doesn't work #7821

Closed
1 task done
Tracked by #7834
retyui opened this issue Dec 17, 2023 · 21 comments
Closed
1 task done
Tracked by #7834

React Native 0.73 npx rnn-link doesn't work #7821

retyui opened this issue Dec 17, 2023 · 21 comments

Comments

@retyui
Copy link
Contributor

retyui commented Dec 17, 2023

What happened?

starting from rn73 *.java files was convened to *.kt
so auto-linking doesn't work properly

npx rnn-link

/tmp/Rn73/node_modules/react-native-navigation/autolink/postlink/path.js:10
exports.rootGradle = mainApplicationJava.replace(/android\/app\/.*\.java/, 'android/build.gradle');
                                         ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at Object.<anonymous> (/Users/davydnarbutovich/tmp/Rn73/node_modules/react-native-navigation/autolink/postlink/path.js:10:42)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/Users/davydnarbutovich/tmp/Rn73/node_modules/react-native-navigation/autolink/postlink/applicationLinker.js:2:12)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

What was the expected behaviour?

no js error, *.kt files supported out of the box

Was it tested on latest react-native-navigation?

  • I have tested this issue on the latest react-native-navigation release and it still reproduces.

Help us reproduce this issue!

No response

In what environment did this happen?

React Native Navigation version: 7.37.2
React Native version: 0.73
Has Fabric (React Native's new rendering system) enabled: (yes/no)
Node version: 18
Device model:
Android version:

@jtich
Copy link

jtich commented Dec 18, 2023

+1

@JailsonSmidi
Copy link

Mesmo problema

@HaNguyenRN
Copy link

+1

@jtich
Copy link

jtich commented Dec 21, 2023

The issue is that the following line in path.js assumes that mainApplication has the java extension, however it's now a kotlin file, which is why mainApplicationJava is undefined.

I was able to get around this issue by changing this line...

var mainApplicationJava = glob.sync('**/MainApplication.java', ignoreFolders)[0];

to the following:

var mainApplicationJava = glob.sync('**/MainApplication.{java,kt}', ignoreFolders)[0];

This way the glob.sync func matches both file extensions.

@elmalakomar
Copy link

+1

@ArianHamdi
Copy link

Same here

@harunisik
Copy link

+1

@pramahaditamaputra
Copy link

is this issue has been solved ?

@stephanepericat
Copy link

i still have this issue as well

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 28, 2024

All, please track #7834 for the official RN73 support 🙏🏻

@brifiction
Copy link

brifiction commented Aug 9, 2024

Hey guys, FYI the similar bug is back / regressed, apologies for appending to this issue. Note, I am using yarn = 4.4.0 and working on the React Native 0.74.5 project. Please take a look and apply a new patch when able 🙏

And I tried using npx rnn-link and script failed, same error as original poster.

node = 22.5.1
yarn = 4.4.0

Error output in terminal

/private/var/www/rndemoapp0745/node_modules/react-native-navigation/autolink/postlink/path.js:10
exports.rootGradle = mainApplicationJava.replace(/android\/app\/.*\.java/, 'android/build.gradle');

Dependency versions installed (with yarn)

"dependencies": {
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.74.5",
    "react-native-navigation": "^7.40.1"
}

Screenshots
image

Temporary solution test
Applied solution from #7821 (comment) and issue resolved.

To change the mainApplicationJava line, at line in path.js

var mainApplicationJava = glob.sync('**/MainApplication.{java,kt}', ignoreFolders)[0];

Thanks a bunch @jtich!

image

@d4vidi
Copy link
Collaborator

d4vidi commented Aug 29, 2024

We're planning to revisit this in the future, but it's going to take a while. We could really use some help from the community with this one, we don't have immediate capacity to address these kind of issues 🙏🏻

@gusilveiramp
Copy link

+1

@gusilveiramp
Copy link

To avoid directly modifying the file in the node_modules folder, I created a postinstall script based on @jtich comment. This script automates the fix for Kotlin support in rnn-link:

  1. Add postinstall to package.json:
"scripts": {
  "postinstall": "node scripts/fix-path.js"
}
  1. Create the fix-path.js file:
/**
 * Fixes an issue with the react-native-navigation's rnn-link command.
 * Reference: https://github.com/wix/react-native-navigation/issues/7821#issuecomment-1865390682
 */
const fs = require('fs');
const path = require('path');

// Path to the path.js file
const filePath = path.join(__dirname, '..', 'node_modules', 'react-native-navigation', 'autolink', 'postlink', 'path.js');

// Replaces the code to support .kt files
fs.readFile(filePath, 'utf8', function (err, data) {
  if (err) {
    return console.log(err);
  }
  const result = data.replace(
    'var mainApplicationJava = glob.sync(\'**/MainApplication.java\', ignoreFolders)[0];',
    'var mainApplicationJava = glob.sync(\'**/MainApplication.{java,kt}\', ignoreFolders)[0];'
  );

  fs.writeFile(filePath, result, 'utf8', function (err) {
    if (err) {return console.log(err);}
    console.log('Fix applied to path.js for Kotlin support.');
  });
});
  1. Run the script:
yarn install  # or yarn postinstall

@gusilveiramp
Copy link

Even though npx rnn-link runs correctly after applying the postinstall script, the Android build still fails with the following error:

Task :react-native-navigation:compileReactNative71DebugKotlin

@rendomnet
Copy link

The issue is that the following line in path.js assumes that mainApplication has the java extension, however it's now a kotlin file, which is why mainApplicationJava is undefined.

I was able to get around this issue by changing this line...

var mainApplicationJava = glob.sync('**/MainApplication.java', ignoreFolders)[0];

to the following:

var mainApplicationJava = glob.sync('**/MainApplication.{java,kt}', ignoreFolders)[0];

This way the glob.sync func matches both file extensions.

Why this is not merged?

@retyui
Copy link
Contributor Author

retyui commented Dec 3, 2024

@rendomnet Because it useless and helps to skip error message, without applying a Kotlin liker code

retyui added a commit to retyui/react-native-navigation that referenced this issue Dec 3, 2024
retyui added a commit to retyui/react-native-navigation that referenced this issue Dec 3, 2024
retyui added a commit to retyui/react-native-navigation that referenced this issue Dec 3, 2024
retyui added a commit to retyui/react-native-navigation that referenced this issue Dec 3, 2024
retyui added a commit to retyui/react-native-navigation that referenced this issue Dec 3, 2024
@retyui
Copy link
Contributor Author

retyui commented Dec 3, 2024

Workaround: You can use a tmp. ver with a fixed rnn-link command. (after linking return to regular RRN version)

# install a version with a fix
yarn add react-native-navigation@https://github.com/retyui/react-native-navigation.git#feat/retyui/add-kotlin-autolinker
# do linking
npx rnn-link
# restore prev. version of RNN
yarn add react-native-navigation # or use our own version

@retyui retyui closed this as completed Dec 3, 2024
@rendomnet
Copy link

rendomnet commented Dec 4, 2024

@retyui Could you confirm that is it working with react-native 0.76.3? Becuase in my case it is not.

@rendomnet
Copy link

Even though npx rnn-link runs correctly after applying the postinstall script, the Android build still fails with the following error:

Task :react-native-navigation:compileReactNative71DebugKotlin

Did you found a solution?

@retyui
Copy link
Contributor Author

retyui commented Dec 4, 2024

@rendomnet It's known problem, and you can find many solutions in github issues. Try searching it to see how to fix it.

retyui added a commit to retyui/react-native-navigation that referenced this issue Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests