# Fix TypeError: crypto.hash Is Not a Function After a Vite 7 Upgrade

Yes. An agent reproduces the dev-server crash on Node 18 next to the build that still passes, moves the Dockerfile and tooling to a supported Node, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-crypto-hash-is-not-a-function/vite/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads what runs where. In a SvelteKit app like AnishSarkar22/Loopr, `package.json` has `dev: vite dev` and `build: vite build`, pins `vite` at `^6.2.6`, which the lockfile resolves to 6.3.5, with `@sveltejs/kit` 2.22.2, `@sveltejs/vite-plugin-svelte` 5.1.0 and `svelte` 5.34.8. The `Dockerfile` builds from `node:18-alpine`, runs `npm ci` and `npm run build`, and ships a second `node:18-alpine` stage that runs `node build`. The build needs the Appwrite variables from `.env.example`, because `src/routes/api/delete-account/+server.ts` imports them from `$env/static/private`; without a `.env`, `vite build` stops there before anything else.

Then it reproduces the states on both Node lines. On Node 22.23.4 and on Node 18.20.8, with `.env` copied from the example, the locked Vite 6.3.5 builds and its dev server starts; 6.3.5 declares `engines.node` as `^18.0.0 || ^20.0.0 || >=22.0.0`. After `npm install vite@7.0.0 @sveltejs/vite-plugin-svelte@6.0.0`, the versions the Kit release supports, `npm run build` still passes on Node 18, but `npm run dev` stops with `error when starting dev server: TypeError: crypto.hash is not a function`. In a bare Vite 7 project the same line appears from `vite optimize` and from the dev server as soon as there is one dependency to pre-bundle, while `vite build` passes, which is why a Docker image on Node 18 can keep building the app while every developer on Node 18 cannot run it.

The cause is in the engines field. Vite 7 declares `^20.19.0 || >=22.12.0` and calls `crypto.hash`, which Node added in 20.12 and 22; on Node 18 `typeof crypto.hash` is `undefined`. Vite 7.3.8 prints `You are using Node.js 18.20.8. Vite requires Node.js version 20.19+ or 22.12+` before the same error, and the current `@sveltejs/vite-plugin-svelte` 6.2.4, whose engines are `^20.19 || ^22.12 || >=24`, fails even earlier on Node 18 with `SyntaxError: The requested module 'node:util' does not provide an export named 'styleText'`.

The fix is the runtime, not a Vite downgrade. The agent moves both `Dockerfile` stages to a current Node LTS image, adds an `engines.node` field and an `.nvmrc` that match Vite's floor, upgrades `vite` and `@sveltejs/vite-plugin-svelte` to their current releases, and runs `npm run build` and `npm run dev` on that Node to show both pass. It leaves `@sveltejs/kit` where it is, since 2.22.2 already accepts Vite 7, and does not touch the Appwrite configuration beyond reading the example file for the build.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "The dev server of this Vite app fails with \"TypeError: crypto.hash is not a function\" after upgrading to Vite 7. Read package.json, the lockfile, the Dockerfile, any .nvmrc or engines field and the env example first, and create a local .env from the example if the build needs it. Run the build and the dev server on the Node the Dockerfile uses and on a current LTS, at the locked Vite and at Vite 7 with the matching Svelte plugin, and quote what each prints, including any engines warning. Explain which Node release added the function Vite calls. Move the Dockerfile stages, an .nvmrc and an engines field to a Node that Vite 7 supports, upgrade vite and the plugin to their current releases, and show the build and dev server pass there. Do not downgrade Vite and do not change application code. Open a pull request that quotes the failing and passing runs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request touching `Dockerfile`, `package.json`, the lockfile and a new `.nvmrc`: both image stages moved from `node:18-alpine` to a current LTS tag, `engines.node` set to Vite 7's floor, and `vite` and `@sveltejs/vite-plugin-svelte` raised to their current releases. The description quotes `TypeError: crypto.hash is not a function` from `npm run dev` on Node 18 at Vite 7.0.0, the `styleText` import error from the current plugin on the same Node, the engines warning Vite 7.3.8 prints, and the passing `build` and `dev` output on the new Node, with a line explaining that `crypto.hash` arrived in Node 20.12 and 22.

A reviewer checks that the production stage moved with the builder stage, that `.nvmrc`, `engines` and the Dockerfile name the same Node line, and that `@sveltejs/kit` was left alone. The run's record has every build and dev-server start on both Node versions with full output, so the before and after can be read rather than taken on trust.

## Run it on every failed Docker build or dev server after a Vite bump

Add an automation to the Project with this prompt and a `github` trigger on `workflow_run.failure`, with `branch_patterns` set to the branches that build images, so a contributor's fork does not start a run. The trigger appends the failed run's event after the prompt, and the agent reads the job and the Node version from its log; a failure that is not a runtime mismatch ends with a one-line answer naming what failed instead. `max_runs_per_hour` caps what a flapping pipeline can start.

From your own server instead, a handler for GitHub's `workflow_run` webhook with `conclusion: failure` sends this body to `POST /o/{org}/sessions` with an API key, the repository in `resources`, and a `request_id` that is a UUID v5 of the run id, so a redelivered event returns the run already started. A `webhook_url` on the key receives `run.completed` with `data.session_url` when the pull request is up.

## Why run it on Rush?

This failure splits along a line no single machine shows: the build passes and the dev server crashes, on Node 18 only. The agent has both Node lines in its sandbox, runs build and dev at the locked and the upgraded Vite on each, and keeps every command and its output in the run's record, so the pull request states which combination fails and why rather than which one happened to be on a laptop.

The fix touches an image, a version file and a manifest that have to agree, and the only proof is a build and a dev server started on the new runtime. The agent does that in the sandbox and quotes it, so the reviewer reads a passing run on the Node the Dockerfile now names instead of trusting that three files were edited consistently.

## Frequently asked questions

### Why does the build pass but the dev server fail?

Vite's dependency optimizer hashes its inputs with `crypto.hash`, and the dev server runs it on start, as does `vite optimize`. A production build of this app does not reach that call on Node 18, so `npm run build` in a `node:18-alpine` image keeps passing while `npm run dev` on the same Node stops at once.

### Which Node do I need?

Vite 7's engines field says `^20.19.0 || >=22.12.0`, and `crypto.hash` exists from Node 20.12 and in every Node 22. The current `@sveltejs/vite-plugin-svelte` asks for `^20.19 || ^22.12 || >=24`, so the pull request picks a current LTS line and names it in the Dockerfile, `.nvmrc` and `engines` together.

### Could the pull request pin Vite 6 instead?

It could, and the prompt forbids it. Vite 6.3.5 runs on Node 18, but the plugin line and Kit releases are moving to Node 20 and 22 as well, so a pin buys weeks. Moving the runtime once fixes the dev server, the image and the next upgrade.

### Why did the build need a .env file?

SvelteKit resolves `$env/static/private` at build time, and `src/routes/api/delete-account/+server.ts` imports `APPWRITE_PROJECT_ID` and two other names from it, so a build with no `.env` fails on that import before Vite does anything else. The agent copies `.env.example` for its own runs and does not commit it.

## More Vite jobs

- [Fix "The CJS build of Vite's Node API is deprecated" Warning in Vite 5](https://getrush.ai/run/fix-vite-cjs-node-api-deprecated/vite/)
- [Upgrade a React App From Vite 5 to the Current Vite Major](https://getrush.ai/run/upgrade-vite/vite/)
- [Add a Bundle Size Budget to a Vite App](https://getrush.ai/run/add-bundle-size-budget/vite/)

## More jobs like this: Fix a bug from an alert

- [Fix "AttributeError: 'Cursor' object has no attribute 'count'" after a PyMongo upgrade](https://getrush.ai/run/fix-cursor-object-has-no-attribute-count/pymongo/)
- [Fix "d3.scale.linear is not a function" after upgrading D3 past version 3](https://getrush.ai/run/fix-d3-scale-linear-is-not-a-function/d3/)
- [Fix "database is locked" Errors in a GORM and SQLite App](https://getrush.ai/run/fix-database-is-locked/gorm/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
