datalayer / jupyter-ui

⚛️ React.js components 💯% compatible with 🪐 Jupyter - Storybook on https://jupyter-ui-storybook.datalayer.tech
https://jupyter-ui.datalayer.tech
Other
321 stars 46 forks source link

Jupyter crashes with pyodide error 'NameError: name 'false' is not defined' when trying to use lite mode #272

Open sok82 opened 1 month ago

sok82 commented 1 month ago

Description

When I'm trying to use Jupyter component liteMode=true and pass python code for execution to Output component I got an error of pyodide with error message

Traceback (most recent call last):
  File "/lib/python311.zip/_pyodide/_base.py", line 573, in eval_code_async
    await CodeRunner(
  File "/lib/python311.zip/_pyodide/_base.py", line 395, in run_async
    await coroutine
  File "<exec>", line 6, in <module>
NameError: name 'false' is not defined

Reproduce

Simplified version of my code

function MyComponent({code, kernel} : {code:string, kernel}) {
const [executeTrigger, setExecuteTrigger] = useState(0);

return <Jupyter 
                  lite={true}
                  useRunningKernelIndex={-1}
                  startDefaultKernel={true}
                  terminals={false}             
              >
                 <Output                    
                        sourceId="src-1"
                        codePre=""
                        autoRun={false}
                        kernel={kernel}
                        code={code}
                        showEditor={false}
                        showControl={false}
                        executeTrigger={executeTrigger}      
              />

</Jupyter>
}

Steps to reproduce

  1. Initialization works fine

  2. I execute code by incrementing executeTrigger

  3. When I set code value to something like

    job_satisfaction_rate_train = pd.read_csv('https://my.domain.com/datasets/dataset.csv')

    execution also doesn't return any error

  4. But when I set code value

    plt.hist(job_satisfaction_rate_train['job_satisfaction_rate'], bins=50);
    plt.grid();

    I got pyodide error NameError: name 'false' is not defined

Browser logs data

Existing JupyterLite ServiceWorkers unregistered
service-manager.ts:60 Registering new JupyterLite ServiceWorker http://localhost:3000/[object Object]
State.ts:167 Kernel Manager is Ready KernelManager
State.ts:202 Starting Kernel Name: python

then

script has an unsupported MIME type ('text/html').
pyodide.asm.js:9 Loading micropip, packaging
pyodide.asm.js:9 Loading micropip, packaging
pyodide.asm.js:9 Loaded micropip, packaging
pyodide.asm.js:9 Loaded micropip, packaging
kernel.js:40 Uncaught (in promise) PythonError: Traceback (most recent call last):
  File "/lib/python311.zip/_pyodide/_base.py", line 573, in eval_code_async
    await CodeRunner(
  File "/lib/python311.zip/_pyodide/_base.py", line 395, in run_async
    await coroutine
  File "<exec>", line 6, in <module>
NameError: name 'false' is not defined
echarles commented 1 week ago

I have tried this recently and was not able to reproduce. @sok82 Are you still facing the issue?