Skip to content

Conversation

@mtshiba
Copy link
Contributor

@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
targets: [
{
src: [join(pyodideDir, "*"), ...PYODIDE_EXCLUDE],
src: [join(pyodideDir, "*").replace(/\\/g, "/"), ...PYODIDE_EXCLUDE],
Copy link
Member

Choose a reason for hiding this comment

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

This makes little sense to me, given that path.join uses the platform-specific path separator. Which path contains the / where windows expects a \?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a statement about this limitation here:

If you are using Windows, make sure to use normalizePath after doing path.resolve or else. \ is a escape charactor in tinyglobby and you should use /.

According to this description, using normalizePath is a more robust approach, so I changed it to use that.

Copy link
Member

Choose a reason for hiding this comment

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

Right, this is a glob and not a path.

I suggest then to call normalizePath(pyodideDir) (or normalize before assigning to pyodideDir) to scope the normalize exactly to where it's necessary.

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
Contributor 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
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