cloudflare / cloudflare/vinext
Failed to resolve shim imports in sandbox environments
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 406
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 120
Description
`vinext@0.0.46` 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.
## Files still wrong in 0.0.46
```js
// 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:
```js
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=` 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 `/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.
```sh
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](https://github.com/user-attachments/files/27309707/vinext-shim-bug-repro.zip)
Contributor guide
Assessment
This issue has not been assessed yet.