Skip to content

browser check for dynamic server module throws error whilst building. #14010

@LumiFae

Description

@LumiFae

Describe the bug

I have a class that helps me manage specific database items, and this class dynamically imports from either the client side database stuff, or server-side (like administration level database stuff). This totally works fine in npm run dev but when it comes to npm run build, the code doesn't build and throws an error, even though it's behind a browser check and none of the server side stuff is saved, only passed on.

Image

Reproduction

Make functions that dynamically import server side modules or client side modules depending on the browser check and then run that function both on the server and the client.

Logs

[vite-plugin-sveltekit-compile] [vite-plugin-sveltekit-guard] Cannot import $lib/server/firebase.ts into client-side code:
- src/routes/[companyId=firestoreid]/+page.svelte imports
,  - $lib/classes/items/certification.ts imports
,    - $lib/classes/items/item.svelte.ts dynamically imports
   - $lib/server/firebase.ts
[vite-plugin-sveltekit-guard] Cannot import $lib/server/firebase.ts into client-side code:
- src/routes/[companyId=firestoreid]/+page.svelte imports
,  - $lib/classes/items/certification.ts imports
,    - $lib/classes/items/item.svelte.ts dynamically imports
   - $lib/server/firebase.ts
    at follow (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/graph_analysis/index.js:65:10)
    at follow (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/graph_analysis/index.js:76:5)
    at follow (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/graph_analysis/index.js:72:5)
    at follow (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/graph_analysis/index.js:72:5)
    at follow (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/graph_analysis/index.js:72:5)
    at Object.check (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/graph_analysis/index.js:84:4)
    at file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/index.js:575:12
    at Array.forEach (<anonymous>)
    at Object.handler (file:///Users/x/Developer/x/app/node_modules/@sveltejs/kit/src/exports/vite/index.js:570:25)
    at file:///Users/x/Developer/x/app/node_modules/rollup/dist/es/shared/node-entry.js:20812:40

System Info

System:
    OS: macOS 15.5
    CPU: (11) arm64 Apple M3 Pro
    Memory: 106.14 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.13.1 - /usr/local/bin/node
    npm: 10.5.2 - /usr/local/bin/npm
  Browsers:
    Edge: 138.0.3351.83
    Safari: 18.5
  npmPackages:
    @sveltejs/adapter-vercel: ^5.6.2 => 5.6.3 
    @sveltejs/kit: ^2.17.2 => 2.19.1 
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.4 
    svelte: ^5.28.2 => 5.28.2 
    vite: ^5.4.18 => 5.4.18

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions