Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot import into client-side code" errors are incredibly difficult to debug #13261

Open
MaddyGuthridge opened this issue Jan 1, 2025 · 1 comment
Labels
feature / enhancement New feature or request

Comments

@MaddyGuthridge
Copy link

MaddyGuthridge commented Jan 1, 2025

Describe the bug

In my project, I have inadvertently imported some server-side code into my front-end code. However, the error message gives no indication of where the import has come from, meaning I have to hunt through hundreds of files to try to find the offending import statement.

Reproduction

  1. Import code from $lib/server/... into client-side code.
  2. Notice that the error gives no indication of where the incorrect import occurs.

Logs

10:21:01 pm [vite] Internal server error: Cannot import $lib/server/data/dataDir.ts into client-side code
      at LoadPluginContext.load (file:///home/maddy/Source/Minifolio/node_modules/@sveltejs/kit/src/exports/vite/index.js:418:12)
      at PluginContainer.load (file:///home/maddy/Source/Minifolio/node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:49064:17)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async loadAndTransform (file:///home/maddy/Source/Minifolio/node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:51869:22)
      at async viteTransformMiddleware (file:///home/maddy/Source/Minifolio/node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:61881:24)

System Info

System:
    OS: Linux 6.12 Fedora Linux 41 (Workstation Edition)
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 50.80 GB / 62.41 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.12.0 - /run/user/1000/fnm_multishells/344514_1735730898683/bin/node
    npm: 10.9.0 - /run/user/1000/fnm_multishells/344514_1735730898683/bin/npm
    bun: 1.1.34 - ~/.bun/bin/bun
  Browsers:
    Chrome: 131.0.6778.204
  npmPackages:
    @sveltejs/adapter-node: ^5.0.1 => 5.2.9 
    @sveltejs/kit: ^2.5.27 => 2.9.0 
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.0 
    svelte: ^5.0.0 => 5.1.12 
    vite: ^5.4.6 => 5.4.10

Severity

annoyance

Additional Information

I understand that I have got a bug in my code somewhere. The issue is that the error's trace-back makes it impossible to quickly determine where the bug is, which is incredibly frustrating. Showing me which file the bad import occurs within would be very helpful.

@TheBeachMaster
Copy link

This and this #5937 are so annoying and I wish the Svelte team would do us a solid and provide usable stack-traces...

@eltigerchino eltigerchino added the feature / enhancement New feature or request label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants