diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index 92a3b6a282..de52fb36be 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -13,7 +13,7 @@ "build": "pnpm run build:peggy && pnpm run build:ts && pnpm run build:worker", "build:peggy": "peggy --cache --format es ./src/ast/peggyParser.peggy", "build:ts": "tsc -b", - "build:worker": "esbuild src/runners/worker.ts --bundle --minify --platform=browser --outfile=dist/runners/esbuild-worker.cjs", + "build:worker": "esbuild src/runners/worker.ts --bundle --minify --platform=browser --format=esm --outfile=dist/runners/esbuild-worker.js", "dev": "tsc -b -w", "clean": "rm -rf dist && rm -f src/ast/peggyParser.js && rm *.tsbuildinfo", "jest": "NODE_OPTIONS=--experimental-vm-modules jest", diff --git a/packages/squiggle-lang/src/runners/WebWorkerRunner.ts b/packages/squiggle-lang/src/runners/WebWorkerRunner.ts index e7d15421b3..b51e770f79 100644 --- a/packages/squiggle-lang/src/runners/WebWorkerRunner.ts +++ b/packages/squiggle-lang/src/runners/WebWorkerRunner.ts @@ -14,18 +14,11 @@ export class WebWorkerRunner extends AnyWorkerRunner { * If you need to touch this code, make sure to check carefully both the components (storybook) and the hub editor. * This configuration and the esbuild configuration in `package.json` are extremely fragile. * - * In particular: - * 1. ESM is problematic:`{ type: "module" }` (with `.mjs` or `.js`)will seemingly work, but cause lots of Turbopack CLI errors; Turbopack fails to analyze `(url, { type: "module" })` parameters correctly, as of Next.js 15.0.3. - * 2. `.js` extension will collide with the default `"type": "module"` in `package.json`, which will lead to Next.js warnings. - * - * So, instead, we bundle the worker to the basic IIFE; see `package.json` for details. - * - * This might cause issues in the future, if we decide to depend on some library that's ESM-only; I'm not sure how good esbuild is for bundling ESM dependencies. - * - * But, for now, it seems like it's working. + * Details here: https://github.com/quantified-uncertainty/squiggle/pull/3456 */ - const url = new URL("./esbuild-worker.cjs", import.meta.url); - this.worker = new Worker(url); + this.worker = new Worker(new URL("./esbuild-worker.js", import.meta.url), { + type: "module", + }); } async getWorker(): Promise { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1275e5f8e2..b7a9ba2bfa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20965,7 +20965,7 @@ snapshots: chalk: 4.1.2 exit: 0.1.2 graceful-fs: 4.2.11 - jest-config: 29.7.0(@types/node@22.9.0)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@22.9.0)(typescript@5.6.3)) + jest-config: 29.7.0(@types/node@20.12.7)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.6.3)) jest-util: 29.7.0 prompts: 2.4.2 transitivePeerDependencies: @@ -21873,7 +21873,7 @@ snapshots: eslint: 8.57.0 eslint-import-resolver-node: 0.3.7 eslint-import-resolver-typescript: 3.5.3(eslint-plugin-import@2.28.1(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.20.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.5.3)(eslint@8.57.0) + eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.20.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.5.3(eslint-plugin-import@2.28.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-jsx-a11y: 6.7.1(eslint@8.57.0) eslint-plugin-react: 7.33.2(eslint@8.57.0) eslint-plugin-react-hooks: 4.6.2(eslint@8.57.0) @@ -21896,7 +21896,7 @@ snapshots: debug: 4.3.6 enhanced-resolve: 5.15.0 eslint: 8.57.0 - eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.20.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.5.3)(eslint@8.57.0) + eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.20.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.5.3(eslint-plugin-import@2.28.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) get-tsconfig: 4.7.5 globby: 13.1.3 is-core-module: 2.13.1 @@ -21916,7 +21916,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-import@2.28.1(@typescript-eslint/parser@6.20.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.5.3)(eslint@8.57.0): + eslint-plugin-import@2.28.1(@typescript-eslint/parser@6.20.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.5.3(eslint-plugin-import@2.28.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): dependencies: array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 @@ -23661,7 +23661,7 @@ snapshots: create-jest: 29.7.0(babel-plugin-macros@3.1.0) exit: 0.1.2 import-local: 3.1.0 - jest-config: 29.7.0(@types/node@22.9.0)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@22.9.0)(typescript@5.6.3)) + jest-config: 29.7.0(@types/node@20.12.7)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.12.7)(typescript@5.6.3)) jest-util: 29.7.0 jest-validate: 29.7.0 yargs: 17.7.2