Skip to content

Vite v4.4.0+ restart dev server crashed by "@sveltejs/kit/vite" plugin. #10349

@hackape

Description

@hackape

Describe the bug

See also vitejs/vite#13735.

This error can easily be triggered by hitting "r" key in vite CLI to restart the dev server.

Reproduction

Stackblitz

Logs

VITE v4.4.1  ready in 1272 ms

  ➜  Local:   http://localhost:5173/     
  ➜  Network: http://169.254.35.252:5173/
  ➜  Network: http://192.168.10.165:5173/
  ➜  Network: http://172.31.96.1:5173/   
  ➜  press h to show help
1:09:14 AM [vite] .env changed, restarting server...

const err = new Error('The server is being restarted or closed. Request is outdated');
                ^

Error: The server is being restarted or closed. Request is outdated
    at throwClosedServerError (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-439026c8.js:43694:17)
    at loadAndTransform (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-439026c8.js:54807:9)
    at async instantiateModule (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-439026c8.js:55738:10) {
  code: 'ERR_CLOSED_SERVER'
}

Node.js v18.16.0

System Info

System:
    OS: macOS 13.2
    CPU: (10) arm64 Apple M2 Pro
    Memory: 155.45 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.0/bin/yarn
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
    pnpm: 8.6.3 - ~/.nvm/versions/node/v18.14.0/bin/pnpm
  Browsers:
    Chrome: 114.0.5735.198
    Edge: 114.0.1823.41
    Safari: 16.3
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: ^1.20.4 => 1.22.1 
    svelte: ^4.0.0 => 4.0.5 
    vite: 4.4.2 => 4.4.2

Severity

annoyance

Additional Information

It is introduced by this vite PR: vitejs/vite#13262.

The error originates from align_exports function call in "@sveltejs/kit/vite", where it calls await vite.ssrLoadModule(...);. This happens in sveltekit plugin's "configureServer" hook, which is tapped when vite restartServer.

And since server._restartPromise = restartServer(server), but vite.ssrLoadModule will eventually call loadAndTransform containing this line: if (server._restartPromise) throwClosedServerError(), this error is always thrown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions