pyodide-kernel icon indicating copy to clipboard operation
pyodide-kernel copied to clipboard

Newer `terser` breaks the production build

Open jtpio opened this issue 2 months ago • 2 comments

After updating dependencies in https://github.com/jupyterlite/pyodide-kernel/pull/226, starting a new kernel using a production of jupyterlite-pyodide-kernel fails with:

Failed to construct 'Worker': Failed to read the 'type' property from 'WorkerOptions':
Cannot convert object to primitive value

In packages/pyodide-kernel/src/kernel.ts, workers are created with:

new Worker(new URL('./comlink.worker.js', import.meta.url), {
  type: 'module',
})

Looking more closely at the built assets:

Dev:

new Worker(new URL(...), {
  type: undefined,
})

Prod (minified):

new Worker(new URL(...), {
  type: s,  // Variable reused - 's' is the pypi import namespace object
})
Image

This seems to be caused by a new version of terser, which likely introduced more aggressive variable reuse optimizations.

The UI tests didn't catch this because they were using the dev build, where the issue doesn't manifest.

jtpio avatar Oct 13 '25 07:10 jtpio

https://github.com/jupyterlite/pyodide-kernel/pull/231 confirmed the issue with the prod build and reverted the terser update for now.

We should look into a proper fix compatible with newer versions of terser and webpack.

jtpio avatar Oct 13 '25 07:10 jtpio

We should look into a proper fix compatible with newer versions of terser and webpack.

Adding the following to https://github.com/jupyterlite/pyodide-kernel/blob/main/packages/pyodide-kernel-extension/webpack.config.js will likely help:

experiments: {
  outputModule: true,
},

jtpio avatar Oct 13 '25 09:10 jtpio