Skip to content

Comments

[ty] fix ty playground initialization and vite optimization issues#21471

Merged
MichaReiser merged 4 commits intoastral-sh:mainfrom
mtshiba:fix-playground-build-win
Nov 25, 2025
Merged

[ty] fix ty playground initialization and vite optimization issues#21471
MichaReiser merged 4 commits intoastral-sh:mainfrom
mtshiba:fix-playground-build-win

Conversation

@mtshiba
Copy link
Collaborator

@mtshiba mtshiba commented Nov 15, 2025

Summary

I tried to build the ty playground on my Windows machine and run it locally, but it didn't work. I got the following error:

$ npm start --workspace ty-playground

> [email protected] prestart
> npm run dev:wasm


> [email protected] dev:wasm
> wasm-pack build ../../crates/ty_wasm --dev --target web --out-dir ../../playground/ty/ty_wasm

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm... 
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.69s
[INFO]: Installing wasm-bindgen...
[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO]: :-) Done in 5.46s
[INFO]: :-) Your wasm pkg is ready to publish at ..\..\playground\ty\ty_wasm.

> [email protected] start
> vite

[vite-plugin-static-copy] Error: No file was found to copy to C:\{omitted}\ruff\playground\node_modules\pyodide\*,!**/*.{md,html},!**/*.d.ts,!**/*.whl,!**/node_modules src.
[vite-plugin-static-copy] No items found.

Also, nothing is displayed when I access localhost:5173. The following error appears in the browser console:

ty_wasm.js?v=16eba020:2195 Uncaught TypeError: Cannot read properties of undefined (reading '__wbindgen_malloc')
at new Workspace (ty_wasm.js?v=16eba020:2195:51)
at Playground.tsx:33:27

This PR fixes the above issues.

First, for the first issue with vite-plugin-static-copy, I addressed it by changing backslashes \ to slashes / in the path name. This is a common Windows-specific path handling issue.

For the other issue, I changed the ty_wasm package import from a relative path to a package name, and excluded ty_wasm from optimizeDeps in vite.config.js.
To be honest, I'm not familiar with vite, so I'm not sure why this worked, but I tried the workaround described here:

vitejs/vite#8427

The above changes are for development purposes only and should not affect the content actually delivered.

Test Plan

N/A

@mtshiba mtshiba marked this pull request as ready for review November 15, 2025 13:10
@AlexWaygood AlexWaygood added playground A playground-specific issue ty Multi-file analysis & type inference labels Nov 15, 2025
export default defineConfig({
plugins: [react(), tailwindcss(), viteStaticCopyPyodide()],
optimizeDeps: { exclude: ["pyodide"] },
optimizeDeps: { exclude: ["pyodide", "ty_wasm"] },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use vite for the production builds. Can you verify that the vite build reported sizes are the same before and after your changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Build results on Ubuntu (@ WSL2):

main:

❯ dust ty/dist
 24K   ┌── Astral.png                │█                                                             │   0%
 20K   │ ┌── pyodide.mjs             │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 20K   │ ├── solidity-CVYD1GVc.js    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 24K   │ ├── tsMode-De4b9PNo.js      │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 36K   │ ├── cssMode-cNRTyZYV.js     │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 36K   │ ├── htmlMode-BieFvPPN.js    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 44K   │ ├── ffi.d.ts                │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 44K   │ ├── jsonMode-B6VJCXeF.js    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 68K   │ ├── pyodide.d.ts            │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 84K   │ ├── pyodide.js.map          │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 84K   │ ├── pyodide.mjs.map         │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 92K   │ ├── codicon-B_Z2XQ3P.ttf    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
112K   │ ├── pyodide-lock.json       │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
144K   │ ├── editor-BhPcksyq.css     │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
396K   │ ├── index-BeD-OYFt.js       │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   1%
1.0M   │ ├── pyodide.asm.js          │███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   4%
2.3M   │ ├── python_stdlib.zip       │█████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   8%
3.5M   │ ├── editor.main-ClkAP-6o.js │████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │  12%
8.2M   │ ├── pyodide.asm.wasm        │██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │  29%
 11M   │ ├── ty_wasm_bg-Bd9OBY4A.wasm│██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │  41%
 28M   ├─┴ assets                    │█████████████████████████████████████████████████████████████ │ 100%
 28M ┌─┴ dist                        │█████████████████████████████████████████████████████████████ │ 100%

#21471:

❯ dust ty/dist
 24K   ┌── Astral.png                │█                                                             │   0%
 20K   │ ┌── pyodide.mjs             │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 20K   │ ├── solidity-CVYD1GVc.js    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 24K   │ ├── tsMode-Bzlyl_WG.js      │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 36K   │ ├── cssMode-BItooz1B.js     │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 36K   │ ├── htmlMode-XS2Ok6yb.js    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 44K   │ ├── ffi.d.ts                │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 44K   │ ├── jsonMode-Bw4_M6_V.js    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 68K   │ ├── pyodide.d.ts            │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 84K   │ ├── pyodide.js.map          │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 84K   │ ├── pyodide.mjs.map         │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
 92K   │ ├── codicon-B_Z2XQ3P.ttf    │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
112K   │ ├── pyodide-lock.json       │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
144K   │ ├── editor-BhPcksyq.css     │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   0%
396K   │ ├── index-B_J2zKKC.js       │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   1%
1.0M   │ ├── pyodide.asm.js          │███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   4%
2.3M   │ ├── python_stdlib.zip       │█████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │   8%
3.5M   │ ├── editor.main-CF30gs3G.js │████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │  12%
8.2M   │ ├── pyodide.asm.wasm        │██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │  29%
 11M   │ ├── ty_wasm_bg-C8Ofe_-K.wasm│██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │  41%
 28M   ├─┴ assets                    │█████████████████████████████████████████████████████████████ │ 100%
 28M ┌─┴ dist                        │█████████████████████████████████████████████████████████████ │ 100%

This result is consistent with what the vite document states.

@mtshiba mtshiba force-pushed the fix-playground-build-win branch from 47ad620 to 6d632b1 Compare November 16, 2025 03:27
@mtshiba mtshiba requested a review from MichaReiser November 25, 2025 02:08
@MichaReiser MichaReiser enabled auto-merge (squash) November 25, 2025 07:38
@MichaReiser MichaReiser merged commit dd15656 into astral-sh:main Nov 25, 2025
36 checks passed
@mtshiba mtshiba deleted the fix-playground-build-win branch November 25, 2025 11:27
carljm added a commit to mtshiba/ruff that referenced this pull request Nov 25, 2025
* main:
  [ty] Implement `typing.override` (astral-sh#21627)
  [ty] Avoid expression reinference for diagnostics (astral-sh#21267)
  [ty] Improve autocomplete suppressions of keywords in variable bindings
  [ty] Only suggest completions based on text before the cursor
  Implement goto-definition and find-references for global/nonlocal statements (astral-sh#21616)
  [ty] Inlay Hint edit follow up (astral-sh#21621)
  [ty] Implement lsp support for string annotations (astral-sh#21577)
  [ty] Add 'remove unused ignore comment' code action (astral-sh#21582)
  [ty] Refactor `CheckSuppressionContext` to use `DiagnosticGuard` (astral-sh#21587)
  [ty] Improve several "Did you mean?" suggestions (astral-sh#21597)
  [ty] Add more and update existing projects in `ty_benchmark` (astral-sh#21536)
  [ty] fix ty playground initialization and vite optimization issues (astral-sh#21471)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

playground A playground-specific issue ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants