Next.js Discord

Discord Forum
\n {\n async function main(){\n let pyodide = await loadPyodide();\n console.log(pyodide.runPython(\"1 + 2\"));\n }\n \n }\n \n )\n}\n\nexport default Python","dateCreated":"2024-08-04T14:02:09.660Z","answerCount":0,"author":{"@type":"Person","name":"XotEmBotZ"}}}

How to use pyodide with next js?

Unanswered
XotEmBotZ posted this in #help-forum
Open in Discord
I am trying to import pyodide but getting this error
Module build failed: UnhandledSchemeError: Reading from "node:child_process" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:child_process
./node_modules/pyodide/pyodide.mjs
./src/components/Python.js

The file
'use client'
import {  } from "pyodide"
import { useEffect, useRef } from "react"

const Python = () => {
    const pyodide = useRef(null)

    useEffect(() => {
      pyodide.current=1
    
    }, [])
    

    return (
        <section>
            <script src="https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js"></script>
            {
                async function main(){
                    let pyodide = await loadPyodide();
                    console.log(pyodide.runPython("1 + 2"));
                }
                
            }
        </section>
    )
}

export default Python

0 Replies