Skip to content

Bun preload plugin fails on Windows due to forward-slash-only regex and missing solid-js/web rule #796

@counter2015

Description

@counter2015

Description

The Bun preload plugin in @opentui/solid/scripts/solid-plugin.ts fails silently on Windows, causing solid-js to load its
server-side rendering (SSR) modules instead of the client-side ones. This results in runtime errors when rendering.

I try to run this locally, and find some problem, Claude Code help me to fix it by change local code, but I'm not familiar with ts and this project, need some help from mantainers to check whether this fix is right or not.

Here is the changed code and analysis from Claude Code.

Image

Root Cause

Two issues in solid-plugin.ts:

1. Regex filters only match forward slashes

The onLoad filters use forward slashes to match paths:

build.onLoad({ filter: /\/node_modules\/solid-js\/dist\/server\.js$/ }, ...)
build.onLoad({ filter: /\/node_modules\/solid-js\/store\/dist\/server\.js$/ }, ...)

On Windows, Bun resolves module paths with backslashes (e.g. D:\project\node_modules\solid-js\dist\server.js), so these regex patterns
never match and the redirect silently fails.

2. Missing rule for solid-js/web/dist/server.js

The plugin redirects solid-js/dist/server.js → solid.js and solid-js/store/dist/server.js → store.js, but there is no rule for
solid-js/web/dist/server.js → web.js.

Since solid-js/web/package.json maps the "node" export condition to dist/server.js, Bun (which matches "node" by default) loads the
SSR version of solid-js/web, leading to errors like:

at render (node_modules/@opentui/solid/index.js:357:17)

Suggested Fix

Use [/\] in regex filters to match both path separators, and add the missing solid-js/web rule:

  build.onLoad({ filter: /[\/\\]node_modules[\/\\]solid-js[\/\\]dist[\/\\]server\.js$/ }, async (args) => {
    const path = args.path.replace("server.js", "solid.js")
    return { contents: await Bun.file(path).text(), loader: "js" }
  })
  build.onLoad({ filter: /[\/\\]node_modules[\/\\]solid-js[\/\\]store[\/\\]dist[\/\\]server\.js$/ }, async (args) => {
    const path = args.path.replace("server.js", "store.js")
    return { contents: await Bun.file(path).text(), loader: "js" }
  })
  build.onLoad({ filter: /[\/\\]node_modules[\/\\]solid-js[\/\\]web[\/\\]dist[\/\\]server\.js$/ }, async (args) => {
    const path = args.path.replace("server.js", "web.js")
    return { contents: await Bun.file(path).text(), loader: "js" }
  })

Environment

  • OS: Windows 11
  • Bun: 1.2.x
  • @opentui/solid: 0.1.76 (also verified unfixed in 0.1.86)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsolidThis relates to the solid package

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions