# Unable to initialize

**URL:** <https://forum.deepar.ai/t/unable-to-initialize/760>\
**Category:** Help & Questions\
**Tags:** web-sdk\
**Created:** [September 3, 2024, 5:47am UTC](https://forum.deepar.ai/t/unable-to-initialize/760 "2024-09-03T05:47:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vegas\_castle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/vegas_castle/32/942_2.png) [@vegas\_castle](https://forum.deepar.ai/u/vegas_castle)\
**Post date:** [September 3, 2024, 5:47am UTC](https://forum.deepar.ai/t/unable-to-initialize/760/1 "2024-09-03T05:47:43Z")

</div>

In a Nextjs project, when I tried to initialize deepar as soon as the page and everything loaded, it works.

```auto
    const loadDeepAr = async () => {
        if(canvasRef.current && !deepArRef.current){
            const deepAR = await deepar.initialize({
                licenseKey: `${process.env.NEXT_PUBLIC_DEEPAR_KEY}`,
                canvas: canvasRef.current,
                effect: deepArEffects.viking_helmet,
                additionalOptions: {
                    cameraConfig: {
                        disableDefaultCamera: true
                    }
                }
            });
            deepArRef.current = deepAR
            deepArRef.current.setVideoElement(videoEl.current!, mirrored)
        }
    }

    useEffect(() => {
        if(canvasRef.current && !deepArRef.current){
            loadDeepAr()
        }
    }, [canvasRef.current, deepArRef.current])

```

But, as soon as It was created as a toggle, it breaks with

> Aborted()

and

> RuntimeError: unreachable executed  
> Vb deepar.esm.js:2  
> Ub deepar.esm.js:2  
> ny deepar.esm.js:2

I’m at lost

```auto
    const toggleDeepAr = () => {
        if(!!canvasRef.current){
            if(!deepArRef.current && enabledTracking){
                deepar.initialize({
                    licenseKey: `${process.env.NEXT_PUBLIC_DEEPAR_KEY}`,
                    canvas: canvasRef.current,
                    effect: deepArEffects.Fire_Effect,
                    additionalOptions: {
                        cameraConfig: {
                            disableDefaultCamera: true
                        }
                    },
                })
                .then((result) => {
                    deepArRef.current = result
                    deepArRef.current.setVideoElement(videoEl.current!, mirrored)
                })
                .catch((err: any) => {
                    console.log(err);
                    addToast({ type: 'error', message: err?.message ?? 'Failed to init deepAr' })
                })
            } else {
                deepArRef.current = undefined
            }
        }
    }

    useEffect(() => {
        toggleDeepAr()
    }, [canvasRef.current, deepArRef.current, enabledTracking, videoEl])

```

The trigger being enabledTracking state.  
I can see in the network that .deepar file (selected effect) and deepar wasm fetched successfully, but dyXzimgMagicFace.wasm and models-68-extreme.bin are missing.

And also, how do you cleanup the process as cleaning the ref isn’t dong anything

> Error: deepar.initialize() called but DeepAR is currently being initialized.

shows up when It get called again
