Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/serve pyodide locally #195

Merged
merged 11 commits into from
Nov 1, 2021
Merged

Conversation

berinhard
Copy link
Owner

Fixes #148

@berinhard
Copy link
Owner Author

For some unknown reason, the same target_sketch.js code works locally as expected, but Pyodide sketches are not running in the local web editor. They keep raising an error when calling async main():

Uncaught SyntaxError: await is only valid in async functions, async generators and modules

I'm not sure what's causing this issue, but any JS help here would be helpful. Here's how to reproduce this:

  1. pip uninstall pyp5js
  2. pip install git+https://github.com/berinhard/pyp5js.git@feature/serve-pyodide-locally
  3. Create and compile a new sketch which uses CDN: pyp5js new online; pyp5js compile online;
  4. Create and compile sketch that runs offline: pyp5js new offline --local; pyp5js compile offline;
  5. Make sure you can see the results from the local version by cd to the sketch dir (where is both online.py and index.html files) and run python -m http.server. When you access http://localhost:8000/` you should see the same sketch behavior for both online and offline version;
  6. Run the server with pyp5js serve --debug and try to access the 2 sketches. Both should raise the error above.

@berinhard
Copy link
Owner Author

Updates on the JS issue. After using addEventListener (via 7f33220) to execute the main entrypoint, the local python server version keeps working, but the web editor doesn't. But now, the error changes to:

Uncaught (in promise) ReferenceError: loadPyodide is not defined
    main http://localhost:5000/sketch/offline/target/target_sketch.js:1688
    <anonymous> http://localhost:5000/sketch/offline/target/target_sketch.js:1704
    EventListener.handleEvent* http://localhost:5000/sketch/offline/target/target_sketch.js:1703
target_sketch.js:1688:5
    <anonymous> http://localhost:5000/sketch/offline/target/target_sketch.js:1704
    AsyncFunctionThrow self-hosted:696
    (Async: async)
    <anonymous> http://localhost:5000/sketch/offline/target/target_sketch.js:1703

@berinhard
Copy link
Owner Author

berinhard commented Nov 1, 2021

The fix was to just remove the async statement from the main() call in the target sketch.

@berinhard berinhard merged commit 147a211 into develop Nov 1, 2021
@berinhard berinhard deleted the feature/serve-pyodide-locally branch November 1, 2021 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace pyodide js code by a custom and local install
1 participant