-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Milestone
Description
Describe the bug
Telefunc allows simple frontend to backend calls, avoiding direct call to fetch.
// The `CreateTodo.telefunc.js` file is not loaded:
// Telefunc transforms `*.telefunc.js` imports into a
// thin HTTP client.
import { onNewTodo } from './CreateTodo.telefunc.js'
...
await onNewTodo({ text })Using telefunc + sveltekit can cause the following issues:
Cannot import $env/static/private into client-side codeCannot import $lib/server/xyz.telefunc.ts into client-side code
Those errors happen at build time and in dev mode, but in dev mode, switching between pages can make it work again. See reproduction repo
Reproduction
https://github.com/magne4000/sveltekit-telefunc-repro
pnpm i && pnpm run dev
The 3 links at the top have the 3 following cases:
- working
- failing because of $env/static/private import
- failing because of $lib/server
Logs
[vite-plugin-svelte-kit] Cannot import $lib/server/test3.telefunc.ts into client-side code:
- .svelte-kit/generated/nodes/4.js
- src/routes/failing/server-folder/+page.svelte
- $lib/server/test3.telefunc.ts
error during build:
Error: Cannot import $lib/server/test3.telefunc.ts into client-side code:
- .svelte-kit/generated/nodes/4.js
- src/routes/failing/server-folder/+page.svelte
- $lib/server/test3.telefunc.ts
at IllegalModuleGuard.assert_legal (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/utils.js:47:11)
at IllegalModuleGuard.assert_legal (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/utils.js:49:9)
at prevent_illegal_rollup_imports (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/utils.js:424:8)
at file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/index.js:357:7
at Array.forEach (<anonymous>)
at Object.handler (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/index.js:349:25)
at file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:22710:40
at async PluginDriver.hookParallel (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:22632:17)
at async file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23763:13
at async catchUnfinishedHookActions (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23088:20)Cannot import $env/static/private into client-side code:
- src/routes/failing/private-env/+page.svelte
- $lib/test2.telefunc.ts
- $env/static/private
Error: Cannot import $env/static/private into client-side code:
- src/routes/failing/private-env/+page.svelte
- $lib/test2.telefunc.ts
- $env/static/private
at IllegalModuleGuard.assert_legal (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/utils.js:47:11)
at IllegalModuleGuard.assert_legal (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/utils.js:49:9)
at prevent_illegal_vite_imports (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/utils.js:437:8)
at Object.result.component (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:93:9)
at async Promise.all (index 1)
at async render_response (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:82:16)
at async render_page (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:276:10)
at async resolve (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/index.js:231:17)
at async respond (file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/index.js:301:20)
at async file:///home/magne/workspace/sveltekit-telefunc/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:406:22System Info
System:
OS: Linux 5.19 undefined
CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
Memory: 23.40 GB / 31.26 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 16.15.0 - ~/.volta/tools/image/node/16.15.0/bin/node
Yarn: 1.22.19 - ~/.volta/tools/image/node/16.15.0/bin/yarn
npm: 8.10.0 - ~/.volta/tools/image/npm/8.10.0/bin/npm
Browsers:
Firefox: 104.0.2
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.72
@sveltejs/kit: next => 1.0.0-next.480
svelte: ^3.44.0 => 3.50.1
vite: ^3.1.0 => 3.1.0Severity
serious, but I can work around it
Additional Information
The .telefunc. files are untouched on server side, but are obviously transformed when used client side. There seems to be a mixup in the dependencies check.
I don't know how difficult of a fix this is, but a hacky workaround could be to exclude .telefunc. files from the check 🤷.
brillout
Metadata
Metadata
Assignees
Labels
No labels