-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
In a monorepo with a SvelteKit library package containing remote functions, the development server runs fine. However, when building, the following error occurs:
[vite-plugin-sveltekit-compile] ../packages/shared/dist/component/ui/Component.svelte (2:27): "createPayment" is not exported by "../packages/sha…
The problem happens if functions are imported by the package itself in Svelte components or in .svelte.ts files and when they are not referenced at the top level of the component or .svelte.ts file.
import {remote} from '$remote/func.remote.js'
const handler = async () => { await remote() } // fails
import {remote} from '$remote/func.remote.js'
await remote() // ok
I am unsure whether this is a Kit issue, @svelte/package, esbuild, or Vite plugin.
There is a workaround for this: reference any of the imported functions (just one is enough) outside the handler or at the top level of the .svelte.ts file.
import {remote} from '$remote/func.remote.js'
remote; // fixes the problem
const handler = async () => { await remote() } // ok
Reproduction
https://github.com/fuwaneko/sveltekit-remote-monorepo-bug
I have left comments in the code and in the README.
Logs
pnpm run -r build
Scope: 2 of 3 workspace projects
packages/shared build$ vite build && npm run prepack
[44 lines collapsed]
│ npm warn Unknown env config "_jsr-registry". This will stop working in the next major version of npm.
│ > [email protected] prepack
│ > svelte-kit sync && svelte-package && publint
│ src/lib -> dist
│ @sveltejs/package found the following issues while packaging your library:
│ You are using SvelteKit-specific imports in your code, but you have not declared a dependency on `@sveltejs/kit` in your `package.json`. Add it t…
│ Running publint v0.3.13 for shared...
│ Packing files with `pnpm pack`...
│ Linting...
│ All good!
└─ Done in 4s
app build$ vite build
│ vite v7.1.7 building SSR bundle for production...
│ transforming...
│ ✓ 204 modules transformed.
│ rendering chunks...
│ vite v7.1.7 building for production...
│ transforming...
│ ✓ 160 modules transformed.
│ ✗ Build failed in 179ms
│ ✗ Build failed in 860ms
│ error during build:
│ [vite-plugin-sveltekit-compile] ../packages/shared/dist/component/ui/Component.svelte (2:27): "createPayment" is not exported by "../packages/sha…
│ file: /mvp/sveltekit-test/packages/shared/dist/component/ui/Component.svelte:2:27
│ 1: <script lang="ts">
│ 2: import { approvePayment, createPayment } from "../../api/pay.remote.js";
│ ^
│ 3: // uncomment for another error
│ 4: // import { Store } from "../stores/index.js";
│ at getRollupError (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:…
│ at error (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:397:42)
│ at Module.error (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:…
│ at Module.traceVariable (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-e…
│ at ModuleScope.findVariable (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/no…
│ at ReturnValueScope.findVariable (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shar…
│ at FunctionBodyScope.findVariable (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/sha…
│ at Identifier.bind (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.…
│ at CallExpression.bind (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-en…
│ at CallExpression.bind (file:///mvp/sveltekit-test/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-en…
└─ Failed in 1.3s at /mvp/sveltekit-test/app
/mvp/sveltekit-test/app:
ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL [email protected] build: `vite build`
Exit status 1
System Info
System:
OS: macOS 26.0
CPU: (10) arm64 Apple M2 Pro
Memory: 195.13 MB / 16.00 GB
Shell: 4.0.6 - /opt/homebrew/Cellar/fish/4.0.6/bin/fish
Binaries:
Node: 24.8.0 - ~/.local/state/fnm_multishells/43125_1758553852090/bin/node
npm: 11.6.0 - ~/.local/state/fnm_multishells/43125_1758553852090/bin/npm
pnpm: 10.17.1 - ~/.local/state/fnm_multishells/43125_1758553852090/bin/pnpm
Browsers:
Chrome: 140.0.7339.186
Safari: 26.0
Severity
serious, but I can work around it
Additional Information
There's a workaround, but I'd prefer not to pollute the code with it.