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

Fails to work in next js #47

Open
penta65 opened this issue Jan 19, 2021 · 2 comments
Open

Fails to work in next js #47

penta65 opened this issue Jan 19, 2021 · 2 comments
Assignees

Comments

@penta65
Copy link

penta65 commented Jan 19, 2021

Import directly result as window not defined error.

Screenshot 2021-01-19 at 11 04 59 PM

While importing dynamically results into

Screenshot 2021-01-19 at 11 05 12 PM

@knobutan
Copy link

knobutan commented Aug 7, 2022

I have exactly the same problem and still unsure how to resolve it. I think I am close, but having a problem calling the init function. The error in question is occurring simply because Next.js renders on the server side whereas normal react renders on client side. window is not defined on the server side, so that essentially you need to delay the init process. So I thought using useEffect() works here, but I am not succeeding...

What I tried

useEffect(() => {
    const appIDInit = async () => {
      await import('ibmcloud-appid-js')
      .then(async (obj) =>{

      try {
        await obj.init({
          clientId: 'XXX',
          discoveryEndpoint: 'XXX'
        });
        setInitDone(true)
      } catch (e) {
          console.log("Init Err")
          console.log(e.message)
          setErrorState(true);
          setErrorMessage(e.message);
      }
      })
    }

    appIDInit()
  },[]);

The above code results in error - obj.init is not a function. Anyone from the dev team aware how I can resolve this issue?

@kishore0549
Copy link

Hi I could see the ibmcloud-appid has a newer version and fixed the window issue. same is not fixed int his library which is effecting us. would you please check and provide a fix for this soon. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants