infinitered / reactotron

A desktop app for inspecting your React JS and React Native projects. macOS, Linux, and Windows.
https://docs.infinite.red/reactotron/
MIT License
14.85k stars 945 forks source link

[RN new architecture] Invalid non-string URL" for scriptURL - Falling back to localhost #1486

Open neeteshraj opened 3 months ago

neeteshraj commented 3 months ago

Describe the bug

I am getting this error in development. getHost: "Invalid non-string URL" for scriptURL - Falling back to localhost.

Steps to reproduce. Create RN app. I am in ios with new architecture enabled. This is the reactoronConfig.ts file import Reactotron, {openInEditor, ReactotronReactNative} from 'reactotron-react-native'; import mmkvPlugin from 'reactotron-react-native-mmkv'; import {reactotronRedux} from 'reactotron-redux'; import {storage} from './store';

import config from '../app.json';

Reactotron.configure({ name: config.name, }) .useReactNative({ networking: { ignoreUrls: /symbolicate/, }, editor: false, errors: {veto: stackFrame => false}, overlay: false, }) .use(openInEditor()) .use(mmkvPlugin({storage})) .use(reactotronRedux()) .connect();

export default Reactotron; and this is the index.js /**

import {AppRegistry} from 'react-native'; import App from './App'; import {name as appName} from './app.json'; import 'react-native-gesture-handler';

if (DEV) { import('@/reactotron.config'); } AppRegistry.registerComponent(appName, () => App);

Reactotron version

5.1.7

maksim-romanov commented 3 months ago

same issue

neeteshraj commented 2 months ago

@maksim-romanov did you find any solutions?

adamsinnott commented 2 months ago

I got the same issue running this recipe but with npm instead of bun https://ignitecookbook.com/docs/recipes/Authentication/

Using Ignite 9.7.1 npx ignite-cli@latest new AuthRecipe --workflow=cng --remove-demo --git --install-deps --packager=npm ✅ What bundle identifier? · com.authrecipe ✅ Where do you want to start your project? · projects/AuthRecipe ✅ ❗EXPERIMENTAL❗Would you like to enable the New Architecture? (y/N) · Yes

After installing I ran: npm run ios

This then gives the following failure:

› Installing on iPhone 15 Pro Max
› Opening on iPhone 15 Pro Max (com.authrecipe)
› Opening exp+authrecipe://expo-development-client/?url=http%3A%2F%2F192.168.1.182%3A8081 on iPhone 15 Pro Max

› Logs for your project will appear below. Press Ctrl+C to exit.
iOS Bundled 20212ms node_modules/expo/AppEntry.js (1698 modules)
 (NOBRIDGE) LOG  Bridgeless mode is enabled
 (NOBRIDGE) WARN  getHost: "Invalid non-string URL" for scriptURL - Falling back to localhost
iOS Bundled 116ms node_modules/expo/AppEntry.js (1 module)
 (NOBRIDGE) LOG  Bridgeless mode is enabled
 (NOBRIDGE) WARN  getHost: "Invalid non-string URL" for scriptURL - Falling back to localhost
adamsinnott commented 2 months ago

I have noticed that in node_modules/reactotron-react-native/src/reactotron-react-native.ts there is this snippet.

const getHost = (defaultHost = "localhost") => {
  try {
    // RN Reference: https://github.com/facebook/react-native/blob/main/packages/react-native/src/private/specs/modules/NativeSourceCode.js
    const scriptURL = NativeModules?.SourceCode?.getConstants().scriptURL
    if (typeof scriptURL !== "string") throw new Error("Invalid non-string URL")

    return getHostFromUrl(scriptURL)
  } catch (error) {
    console.warn(`getHost: "${error.message}" for scriptURL - Falling back to ${defaultHost}`)
    return defaultHost
  }
}

When you inspect it, you can see that NativeModules is an empty object {}, thus no SourceCode and no getConstants function. It is this section that is causing the error to be thrown.

Not sure I have the right file but the React Native code that is referenced was last changed 6 months ago and it looks to use new architecture.

I'm going to try with turning new architecture off and see how far I get.

saintyusuf commented 2 months ago

is there any update about this issue?

saintyusuf commented 2 months ago

is there any update about this issue?

i solved it very quickly.

i was installing pods with RCT_NEW_ARCH_ENABLED=1 pod install, and getting that error when app starts everytime.

i installed pods without new arch and problem solved. so, just do pod install in ios folder and try to start app just like that.

RoyRao2333 commented 2 months ago

Is there any solutions with the new arch enabled?

adamsinnott commented 2 months ago

I tried using this react native url polyfill to see if that worked but it didn't (or I didn't implement it correctly). Moving to the old architecture worked though. Not a long term possibility though.

morganick commented 2 months ago

Hey folks, looks like the interface we were using here no longer exists in new arch. I was hoping this was a simple fix I could do while we were at Chain React Conf.

Looks like it will be more involved. Stay tuned.

denysoleksiienko commented 1 month ago

any update for the new arch?

morganick commented 1 month ago

@mark and I went over this last week. I got him up to speed with my research on the topic. Unfortunately, I haven't had a spare moment to work on it.

We feel the same pain as we prepare our applications for the new arch.

markrickert commented 1 month ago

lol Wrong Mark, @morganick :P

Thanks for the trace @adamsinnott. We're going to have to figure out where this variable lives in the new architecture. I'm on a deadline crunch right now but can probably look into this after.

For now, i've silenced the warning with:

if (__DEV__) {
  LogBox.ignoreLogs([
    'getHost: "Invalid non-string URL" for scriptURL - Falling back to localhost',
  ])
}
mym0404 commented 2 weeks ago

Workaround for ignoring warning.

  const _ = console.warn;
  console.warn = () => {};
  LogBox.ignoreLogs(['Invalid non-string URL']);
  const Reactotron = require('reactotron-react-native').default;
  console.warn = _;