Skip to content

Build error when using is used in a module exporting remote functions #14470

@dadezzz

Description

@dadezzz

Describe the bug

When initializing variables with using varName = something the build fails with an error related to a nested export.

Reproduction

https://github.com/dadezzz/sveltekit-using-reproduction

Logs

> bun run build
$ vite build
vite v7.1.6 building SSR bundle for production...
✓ 180 modules transformed.
46 |     }
47 |   }
48 |   let er;
49 |   if (args.length > 0)
50 |     er = args[0];
51 |     throw er;
                 ^
error: 66 |   export default $$_self_$$;;
       ^
error: Unexpected export
    at /home/davide/Documents/sveltekit-using-reproduction/.svelte-kit/output/server/chunks/remote-62b3f9.js:66:3
      at emitError (node:events:51:13)
      at #onError (node:worker_threads:226:14)
✗ Build failed in 1.44s
error during build:
[vite-plugin-sveltekit-compile] Failed with code 1
    at <anonymous> (/home/davide/Documents/sveltekit-using-reproduction/node_modules/@sveltejs/kit/src/utils/fork.js:65:17)
    at emit (node:events:95:22)
    at #onClose (node:worker_threads:216:44)
error: script "build" exited with code 1

System Info

System:
    OS: Linux 6.16 Fedora Linux 42 (KDE Plasma Desktop Edition)
    CPU: (16) x64 AMD Ryzen 7 5825U with Radeon Graphics
    Memory: 1.94 GB / 11.49 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    bun: 1.2.22 - ~/.bun/bin/bun

Severity

blocking an upgrade

Additional Information

It seems that the error started appearing after upgrading to sveltekit 2.39.0, specifically with the export statement introduced by #14293

This is .svelte-kit/output/server/chunks/remote-62b3f9.js:

var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
var __typeError = (msg) => {
  throw TypeError(msg);
};
var __using = (stack, value, async) => {
  if (value != null) {
    if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
    var dispose, inner;
    if (async) dispose = value[__knownSymbol("asyncDispose")];
    if (dispose === void 0) {
      dispose = value[__knownSymbol("dispose")];
      if (async) inner = dispose;
    }
    if (typeof dispose !== "function") __typeError("Object not disposable");
    if (inner) dispose = function() {
      try {
        inner.call(this);
      } catch (e) {
        return Promise.reject(e);
      }
    };
    stack.push([async, dispose, value]);
  } else if (async) {
    stack.push([async]);
  }
  return value;
};
var __callDispose = (stack, error, hasError) => {
  var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _2) {
    return _2 = Error(m), _2.name = "SuppressedError", _2.error = e, _2.suppressed = s, _2;
  };
  var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
  var next = (it) => {
    while (it = stack.pop()) {
      try {
        var result = it[1] && it[1].call(it[2]);
        if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
      } catch (e) {
        fail(e);
      }
    }
    if (hasError) throw error;
  };
  return next();
};
import { q as query } from "./app-server.js";
import "@sveltejs/kit/internal/server";
import "@sveltejs/kit";
import { init_remote_functions } from "@sveltejs/kit/internal";
var _stack = [];

// In this case there is this `try` block that is added to run the dispose function.
// When using `const` this is not present.
try {
  var $$_self_$$ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
    __proto__: null,
    get test() {
      return test;
    }
  }, Symbol.toStringTag, { value: "Module" }));
  var a = __using(_stack, {}, true);
  var test = query(() => {
  });
  init_remote_functions($$_self_$$, "src/lib/test.remote.ts", "62b3f9");
  for (const [name, fn] of Object.entries($$_self_$$)) {
    fn.__.id = "62b3f9/" + name;
    fn.__.name = name;
  }

  // And this is the problematic export statement.
  export default $$_self_$$;;
} catch (_) {
  var _error = _, _hasError = true;
} finally {
  var _promise = __callDispose(_stack, _error, _hasError);
  _promise && await _promise;
}
export {
  test as t
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions