skip to Main Content

this is my function

async function generateImage() {
    try {
      const response = await openai.createImage({
        prompt: 'a white siamese cat',
        n: 1,
        size: '1024x1024',
      });
      console.log(response);
    } catch (error) {
      console.error(error);
    }
  }

i am getting this error when using on mobile :
Error: URL.search is not implemented

i am really stuck in this one so any help is appreciated

2

Answers


  1. Chosen as BEST ANSWER

    i found the solution you have to install npm install react-native-url-polyfill and import "react-native-url-polyfill/auto" in your App.js


  2. You should use react-native-url-polyfill. It’s a homemade polyfill to implement the URL API.

    $ yarn add react-native-url-polyfill
    

    or

    $ npm install react-native-url-polyfill --save
    

    At the top of your entry-point file (index.js), the polyfill will be automatically applied.

    /**
     * @format
     */
    
    import "react-native-url-polyfill/auto"
    import {AppRegistry} from 'react-native';
    import App from './App';
    import {name as appName} from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    
    

    Then just use the url api in any files without any import

        const _url = new URL(url)
        const params = _url.searchParams
        const routeName = _url.hostname
        ...
    

    I hope it will help 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search