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

[BUG] Compilation of Bokeh extension fails in the presence of a package.json file with type: module #13786

Open
mdickinson opened this issue Mar 28, 2024 · 1 comment
Labels

Comments

@mdickinson
Copy link

Software versions

Python version : 3.12.2 (main, Feb 10 2024, 11:36:40) [Clang 14.0.3 (clang-1403.0.22.14.1)]
IPython version : (not installed)
Tornado version : 6.4
Bokeh version : 3.4.0
BokehJS static path : /Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static
node.js version : v20.11.1
npm version : 10.2.4
jupyter_bokeh version : (not installed)
Operating system : macOS-13.6.4-x86_64-i386-64bit

Browser name and version

Not applicable

Jupyter notebook / Jupyter Lab version

Not applicable

Expected behavior

I've been developing a Bokeh extension as part of a codebase that contains a mix of Python and JavaScript / TypeScript. We're using ES modules in preference to CommonJS modules for JavaScript, where possible.

When running an example Panel app that used the Bokeh extension the TypeScript compilation step for that extension was failing with an error ending with Error: Cannot find module 'assert' (full traceback below). I tracked the cause of this back to the use of "type": "module" in my package.json file.

It turns out that a package.json file anywhere above the code being compiled has the same effect: I can install a working extension into a fresh .venv, see everything working as normal, then add a package.json file next to that venv with the offending "type": "module" declaration in it, and the Bokeh extension compilation now fails.

Here are the steps I took. I regret that I'm not currently in a position to share the panel_jsme extension, but I suspect that the problem should be reproducible with any current TypeScript-using Bokeh extension module.

  • Created a clean Python 3.12 venv on my Desktop with python -m venv --clear .venv && source .venv/bin/activate
  • Installed a working Panel+Bokeh extension into it with python -m pip install panel_jsme-1.1.0.dev1+gc3cb2e6-py3-none-any.whl
  • Ran an example Panel app that used the extension, which displayed in the browser as expected
  • Added a minimal package.json file next to the .venv directory, with echo '{ "type": "module" }' > package.json
  • Ran the example app again: the browser showed an HTTP 500 error, and the console gave the traceback shown below.

Observed behavior

After adding the extra package.json file next to the .venv, when I launched the example application the browser showed an HTTP 500 error and the console showed a traceback.

(.venv) mdickinson@mirzakhani Desktop % python simple_app.py
Launching server at http://localhost:64928
Uncaught exception GET / (::1)
HTTPServerRequest(protocol='http', host='localhost:64928', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/tornado/web.py", line 1790, in _execute
    result = await result
             ^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/panel/io/server.py", line 552, in get
    page = server_html_page_for_session(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/panel/io/server.py", line 308, in server_html_page_for_session
    bundle = bundle_resources(doc.roots, resources)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/panel/io/resources.py", line 424, in bundle_resources
    ext = bundle_models(None)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 309, in bundle_models
    _bundle_cache[key] = bundle = _bundle_models(custom_models)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 515, in _bundle_models
    custom_impls = _compile_models(custom_models)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 492, in _compile_models
    compiled = nodejs_compile(impl.code, lang=impl.lang, file=impl.file)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 109, in nodejs_compile
    output = _run_nodejs([compilejs_script], dict(code=code, lang=lang, file=file, bokehjs_dir=os.fspath(bokehjs_dir)))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 443, in _run_nodejs
    return _run(_nodejs_path(), argv, input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 438, in _run
    raise RuntimeError(errout.decode('utf-8'))
RuntimeError: file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:90
          const err = new Error("Cannot find module '" + name + "'");
                      ^

Error: Cannot find module 'assert'
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:90:23)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:314:13)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:265:36)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:166:37)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:120:16
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:159:1
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:33:17 {
  code: 'MODULE_NOT_FOUND'
}

Node.js v20.11.1

500 GET / (::1) 568.92ms

Example code

Sorry, I don't have example code beyond what's described above.

Stack traceback or browser console output

Console traceback ...

(.venv) mdickinson@mirzakhani Desktop % python simple_app.py
Launching server at http://localhost:64928
Uncaught exception GET / (::1)
HTTPServerRequest(protocol='http', host='localhost:64928', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/tornado/web.py", line 1790, in _execute
    result = await result
             ^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/panel/io/server.py", line 552, in get
    page = server_html_page_for_session(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/panel/io/server.py", line 308, in server_html_page_for_session
    bundle = bundle_resources(doc.roots, resources)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/panel/io/resources.py", line 424, in bundle_resources
    ext = bundle_models(None)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 309, in bundle_models
    _bundle_cache[key] = bundle = _bundle_models(custom_models)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 515, in _bundle_models
    custom_impls = _compile_models(custom_models)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 492, in _compile_models
    compiled = nodejs_compile(impl.code, lang=impl.lang, file=impl.file)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 109, in nodejs_compile
    output = _run_nodejs([compilejs_script], dict(code=code, lang=lang, file=file, bokehjs_dir=os.fspath(bokehjs_dir)))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 443, in _run_nodejs
    return _run(_nodejs_path(), argv, input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 438, in _run
    raise RuntimeError(errout.decode('utf-8'))
RuntimeError: file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:90
          const err = new Error("Cannot find module '" + name + "'");
                      ^

Error: Cannot find module 'assert'
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:90:23)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:314:13)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:265:36)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:166:37)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:120:16
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:159:1
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:33:17 {
  code: 'MODULE_NOT_FOUND'
}

Node.js v20.11.1

500 GET / (::1) 568.92ms

Screenshots

No response

@mdickinson
Copy link
Author

Update: I can reproduce without the panel-jsme extension. Below is a zsh shell session transcript. After installing Bokeh 3.4.0 into a clean Python 3.12 venv and also cloning the current Bokeh repo:

  • Running bokeh/examples/advanced/extensions/putting_together.py brings up the expected example app
  • After creating a package.json file alongside the venv, running the same Python file gives a traceback.
mdickinson@mirzakhani Desktop % python -m venv --clear .venv                    
mdickinson@mirzakhani Desktop % source .venv/bin/activate
(.venv) mdickinson@mirzakhani Desktop % python -m pip install -q bokeh
(.venv) mdickinson@mirzakhani Desktop % git clone --quiet git@github.com:bokeh/bokeh.git
(.venv) mdickinson@mirzakhani Desktop % python bokeh/examples/advanced/extensions/putting_together.py 
(.venv) mdickinson@mirzakhani Desktop % echo '{ "type": "module" }' > package.json
(.venv) mdickinson@mirzakhani Desktop % python bokeh/examples/advanced/extensions/putting_together.py
Traceback (most recent call last):
  File "/Users/mdickinson/Desktop/bokeh/examples/advanced/extensions/putting_together.py", line 21, in <module>
    show(layout)
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/io/showing.py", line 149, in show
    return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/io/showing.py", line 200, in _show_with_state
    _show_file_with_state(obj, state, new, controller)
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/io/showing.py", line 181, in _show_file_with_state
    filename = save(obj, state=state)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/io/saving.py", line 98, in save
    _save_helper(obj, filename, resources, title, template, theme)
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/io/saving.py", line 164, in _save_helper
    html = file_html(obj, resources=resources, title=title, template=template or FILE, theme=theme)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/embed/standalone.py", line 361, in file_html
    bundle = bundle_for_objs_and_resources([doc], resources)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/embed/bundle.py", line 208, in bundle_for_objs_and_resources
    ext = bundle_models(models)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 309, in bundle_models
    _bundle_cache[key] = bundle = _bundle_models(custom_models)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 515, in _bundle_models
    custom_impls = _compile_models(custom_models)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 492, in _compile_models
    compiled = nodejs_compile(impl.code, lang=impl.lang, file=impl.file)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 109, in nodejs_compile
    output = _run_nodejs([compilejs_script], dict(code=code, lang=lang, file=file, bokehjs_dir=os.fspath(bokehjs_dir)))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 443, in _run_nodejs
    return _run(_nodejs_path(), argv, input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/util/compiler.py", line 438, in _run
    raise RuntimeError(errout.decode('utf-8'))
RuntimeError: file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:90
          const err = new Error("Cannot find module '" + name + "'");
                      ^

Error: Cannot find module 'assert'
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:90:23)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:314:13)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:265:36)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at Object._ (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:166:37)
    at require (file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:108:21)
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:120:16
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:159:1
    at file:///Users/mdickinson/Desktop/.venv/lib/python3.12/site-packages/bokeh/server/static/js/compiler.js:33:17 {
  code: 'MODULE_NOT_FOUND'
}

Node.js v20.11.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant