jeffreylanters / react-unity-webgl

React Unity WebGL provides a modern solution for embedding Unity WebGL builds in your React Application while providing advanced APIs for two way communication and interaction between Unity and React.
https://react-unity-webgl.dev
Apache License 2.0
1.75k stars 162 forks source link

Unity, useUnityContext not found in 'react-unity-webgl' #461

Closed nwoodr94 closed 2 years ago

nwoodr94 commented 2 years ago

Please avoid duplicates

Language and Compiler

Babel and WebPack JavaScript

What environment are you using?

Local Development Server

When does your problem occur?

While writing code

What does your problem relate to?

The problem seems React related

React-Unity-WebGL Version

8.8.0

React Version

18.1.0

Unity Version

2021.3.5f1

What happened?

import { Unity, useUnityContext } from "react-unity-webgl";

Produces the following error:

export 'useUnityContext' (imported as 'useUnityContext') was not found in 'react-unity-webgl' (possible exports: UnityContext, __esModule, default)

Reproducible test case

Copy and paste the example code (from https://react-unity-webgl.dev/docs/getting-started/hello-world)

The code does not compile.

import React from "react";
import { Unity, useUnityContext } from "react-unity-webgl";
function App() {
  const { unityProvider } = useUnityContext({
    loaderUrl: "path/to/my/loader.js",
    dataUrl: "path/to/my/build.data",
    frameworkUrl: "path/to/my/build.framework",
    codeUrl: "path/to/my/build.wasm",
  });
  return <Unity unityProvider={unityProvider} />;
}

image

Would you be interested in contributing a fix?

jeffreylanters commented 2 years ago

Hi. Would it be possible for you to share your Webpack configuration?

nwoodr94 commented 2 years ago

Hi, I took a look at a coworker's package.json and noticed that he has an updated version.

I was on 8.8.0, but after upgrading to 9.0.4, this issue went away.

I'm using react-scripts through create-react-app, so I don't have immediate access to the Webpack.

jeffreylanters commented 2 years ago

Ah perfect! Thanks for letting me know. Happy coding!