wasmerio / wasmer-js

Monorepo for Javascript WebAssembly packages by Wasmer
https://wasmerio.github.io/wasmer-js/
MIT License
914 stars 81 forks source link

Wasmer fails to load in React application created with create-react-app #402

Closed turingbuilder closed 2 days ago

turingbuilder commented 8 months ago

I am trying to use "@wasmer/sdk" from a single page React application that was created using create-react-app.

The error reported in the console is:

Not allowed to load local resource: file:///Users/.../node_modules/@wasmer/sdk/dist/WasmerSDK.js

I installed the SDK via:

npm i "@wasmer/sdk"    # Installs "@wasmer/sdk": "^0.6.0",

In the React component Wasmer is loaded like this:

import { init, Directory, Wasmer } from "@wasmer/sdk";

...

export default WasmerContext(...) {
    const [python, setPython] = useState<null | Wasmer>(null);
    useEffect(() => {
        import("@wasmer/sdk").then(imported => {
            imported.init().then(() => {
                console.log("Wasmer loaded");
                imported.Wasmer.fromRegistry("python/python").then(python => {
                    if (!python) {
                        console.log("wasmer runtime loaded python");
                        setPython(python);
                    }
                });
            })
        });
    }, [])

    ...
}

At no place in the application do I explicitly call for the "file:///Users/.../node_modules/@wasmer/sdk/dist/WasmerSDK.js" URL, so I assume that somewhere in the initialization code of Wasmer it must be embedding that URL.

This is a production build, built using the command:

npm run build
linear[bot] commented 8 months ago

SDK-81 Wasmer fails to load in React application created with create-react-app

jonathanpv commented 6 months ago

I get the same error with create-next-app

Decided wasn't feasible to use nextjs + wasmer but maybe I'm not investigating hard enough