sveltejs / sveltejs/kit

`read()` has inconsistent results when run in `run` vs. `preview`

Open
#14,468 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

vite
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

When calling read() in a Remote function which is using an aliased route:

read("$data/myFile.txt");

where data is a directory called "data" in the root of the project.

read() results in the following error: Error: Asset does not exist: data/myFile.txt when running npm run preview but fetches the file without issue when run in the dev server.

Whether you define an alias in svelte.config.js or not doesn't appear to make any difference.

It's worth noting that trying to fetch the file with fs.readFileSync also doesn't appear to work

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-jr3n9eow?file=src%2Froutes%2Ffetch.remote.ts

Had to reproduce since the problem actually exists when running npm run build rather than npm run dev, but the setup to recreate it is in that link.

Logs

System Info
System:
    OS: Linux 6.16 EndeavourOS
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 15.90 GB / 30.45 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.8.0 - /usr/bin/node
    npm: 11.6.0 - /usr/bin/npm
    pnpm: 10.16.1 - /usr/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.1.0
    @sveltejs/adapter-node: ^5.3.2 => 5.3.2
    @sveltejs/kit: ^2.22.0 => 2.38.1
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.2.0
    svelte: ^5.0.0 => 5.38.10
    vite: ^7.0.4 => 7.1.5
Severity

blocking an upgrade

Additional Information

There's a good chance there is another workaround for this, but even after having asked in the Discord I'm not able to find one.

This is blocking me from being able to consistently read files from the server using the new Remote functions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction and its src/routes/fetch.remote.ts entry point, then compare npm run dev with npm run build and npm run preview. Check the related svelte.config.js alias setup and verify that read("$data/myFile.txt") resolves the same file in both modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript, vite
Domain
build-system, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.