Skip to content

Failed to resolve shim imports in sandbox environments #1031

@eashish93

Description

@eashish93

[email protected] ships two dist/server/*.js files that still import a shim via a relative path, which #1006 was meant to eliminate. The same vite:import-analysis failure that #1001 / #1006 fixed is back when running under @cloudflare/sandbox SDK.

Image

Files still wrong in 0.0.46

// dist/server/app-page-boundary-render.js:3
// dist/server/app-page-route-wiring.js:3
import { LayoutSegmentProvider } from "../shims/layout-segment-context.js";

Should be:

import { LayoutSegmentProvider } from "vinext/shims/layout-segment-context";

…matching the pattern #1006 applied to the other 67 imports across 34 files.

Symptom

[plugin:vite:import-analysis] Failed to resolve import
"/workspace/node_modules/vinext/dist/shims/layout-segment-context.js"
from "virtual:vite-rsc/client-in-server-package-proxy/%2Fworkspace%2Fnode_modules%2Fvinext%2Fdist%2Fshims%2Flayout-segment-context.js"

Fires on first paint inside a @cloudflare/sandbox-managed container, every time.

Why plain vinext dev doesn't show it

Vite's optimizeDeps pre-bundles the shim and rewrites the absolute path import to ?v=<hash> form, masking it. Under the @cloudflare/sandbox SDK invocation path the optimizer cache misses, so the raw absolute path reaches import-analysis.normalizeUrl — which treats leading / as URL-relative-to-server-root, so /workspace/foo resolves to <root>/workspace/foo = /workspace/workspace/foo and fails.

Versions

vinext 0.0.46
@vitejs/plugin-rsc ^0.5.25
vite 8.0.10
@cloudflare/vite-plugin ^1.35.0
@cloudflare/sandbox ^0.9.2

Fix

Apply #1006's transform to those two files. Worth checking why the regression test added in #1006 didn't catch this in CI for 0.0.46.

Reproduce

Zip attached. README inside has the full mechanism walkthrough.

unzip vinext-shim-bug-repro.zip
cd vinext-shim-bug-repro/main
bun install
bun run dev
# open http://localhost:5200/ → click Start sandbox

vinext-shim-bug-repro.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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