Newer `terser` breaks the production build
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
})
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.
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.
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,
},