Skip to content

Cannot access '' before initialization #14679

@AndreasHald

Description

@AndreasHald

Describe the bug

Build fails on a certain remote function setup.

ReferenceError [Error]: Cannot access 'schema' before initialization
    at file:///Users/hald/Documents/svelte-kit-remote-function-reproduction/.svelte-kit/output/server/chunks/remote-1e3r2ap.js:15:26
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
    at async analyse (file:///Users/hald/Documents/svelte-kit-remote-function-reproduction/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:173:34)
    at async MessagePort.<anonymous> (file:///Users/hald/Documents/svelte-kit-remote-function-reproduction/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)

The reproduction attempts to illustrate the setup as simply as possible but what we are doing on a high level is defining table columns using a const

export const tableSetup = {
   name: {
      cell: SomeComponent,
      type: 'text',
      facet: 'some-facet-type',
      sortable: true,
      ...
   }
}

And then inferring the schema for remote functions based on that

export const schema = buildSchemaFromTableSetup(tableSetup)

That way when calling remote functions, you can get types on your filtering, sorting and faceting of the table rows which is really nice.

However when updating to the latest version of SvelteKit building this fails. We are currently building it successfully on 2.38.1

Reproduction

https://github.com/21RISK/sveltekit-remote-function-reproduction

reproduction created from npx sv create with as minimal changes as possible to highlight issue. run npm run build to see error

Logs

node:internal/event_target:1101
  process.nextTick(() => { throw err; });
                           ^
ReferenceError [Error]: Cannot access 'schema' before initialization
    at file:///Users/hald/Documents/svelte-kit-remote-function-reproduction/.svelte-kit/output/server/chunks/remote-1e3r2ap.js:14:26
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
    at async analyse (file:///Users/hald/Documents/svelte-kit-remote-function-reproduction/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:173:34)
    at async MessagePort.<anonymous> (file:///Users/hald/Documents/svelte-kit-remote-function-reproduction/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)

Node.js v22.12.0

System Info

System:
    OS: macOS 26.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 255.36 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - /Users/hald/.nvm/versions/node/v22.12.0/bin/node
    npm: 11.4.2 - /Users/hald/.nvm/versions/node/v22.12.0/bin/npm
  Browsers:
    Chrome: 141.0.7390.67
    Firefox: 137.0.2
    Safari: 26.0
  npmPackages:
    @sveltejs/adapter-auto: ^6.1.0 => 6.1.1 
    @sveltejs/kit: ^2.43.2 => 2.46.4 
    @sveltejs/vite-plugin-svelte: ^6.2.0 => 6.2.1 
    svelte: ^5.39.5 => 5.39.11 
    vite: ^7.1.7 => 7.1.9

Severity

blocking an upgrade

Additional Information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions