reactotron icon indicating copy to clipboard operation
reactotron copied to clipboard

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

Open neeteshraj opened this issue 1 year ago • 12 comments

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<ReactotronReactNative>({storage})) .use(reactotronRedux()) .connect();

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

  • @format */

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

neeteshraj avatar Jun 19 '24 17:06 neeteshraj

same issue

maksim-romanov avatar Jun 27 '24 11:06 maksim-romanov

@maksim-romanov did you find any solutions?

neeteshraj avatar Jul 04 '24 11:07 neeteshraj

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 avatar Jul 05 '24 09:07 adamsinnott

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.

adamsinnott avatar Jul 05 '24 11:07 adamsinnott

is there any update about this issue?

saintyoseph avatar Jul 16 '24 17:07 saintyoseph

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.

saintyoseph avatar Jul 16 '24 20:07 saintyoseph

Is there any solutions with the new arch enabled?

RoyRao2333 avatar Jul 22 '24 08:07 RoyRao2333

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.

adamsinnott avatar Jul 22 '24 16:07 adamsinnott

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.

morganick avatar Jul 23 '24 05:07 morganick

any update for the new arch?

denysoleksiienko avatar Aug 19 '24 10:08 denysoleksiienko

@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.

morganick avatar Aug 19 '24 12:08 morganick

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',
  ])
}

markrickert avatar Aug 19 '24 15:08 markrickert

Workaround for ignoring warning.

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

mym0404 avatar Sep 11 '24 01:09 mym0404

ReactotronConfig.js:1 getHost: "Invalid non-string URL" for scriptURL - Falling back to localhost

"react-native": "0.76.1",
import Reactotron, {
  networking,
  trackGlobalErrors,
} from 'reactotron-react-native';
import { reactotronRedux } from 'reactotron-redux';

const reactotron = Reactotron.configure()
  .use(reactotronRedux())
  .use(networking())
  .use(trackGlobalErrors())

  .connect();

export default reactotron;

Edit: The new version has fixed this.

FernandoAOborges avatar Oct 30 '24 16:10 FernandoAOborges