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

SPA mode fails when importing code with client-side only variables (worked prior 1.0.0-next.405) #5909

Closed
rob-balfre opened this issue Aug 16, 2022 · 1 comment · Fixed by #5930

Comments

@rob-balfre
Copy link

Describe the bug

Importing code into a Svelte file that contains client-side only variables like location will cause vite errors in dev and build.

Reproduction

Uses: @sveltejs/adapter-static and SSR: false

https://stackblitz.com/github/rob-balfre/sveltekit-static-bug?file=src%2Froutes%2F%2Bpage.svelte

Running dev will show location is not defined.

Only errors if location is called via an import.

Logs

❯ npm install && npm run dev
warn preInstall No description field
warn preInstall No repository field
warn preInstall No license field
┌ [1/4] 🔍  Resolving dependencies
└ Completed in 0.064s
┌ [2/4] 🚚  Fetching dependencies
│ info pruneDeps Excluding 13 dependencies. For more information use `--verbose`.
└ Completed in 0.948s
┌ [3/4] 🔗  Linking dependencies
└ Completed in 0.186s
info security We found `install` scripts which turbo skips for security reasons. For more information see
https://turbo.sh/install-scripts.
├─ @sveltejs/[email protected]
└─ [email protected]
info Some packages were automatically replaced with polyfills. For more information see
https://turbo.sh/polyfills.
└─ [email protected] => [email protected]

success Saved lockfile "package-lock.json"
success Updated "package.json"

success Install finished in 1.23s
$ vite dev

  VITE v3.0.7  ready in 1600 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
location is not defined
ReferenceError: location is not defined
    at /src/lib/foo.js:2:10
    at instantiateModule (file:///home/projects/kkviylzwo.github/node_modules/vite/dist/node/chunks/dep-0f13c890.js:50549:15)

System Info

System:
    OS: macOS 12.5
    CPU: (8) arm64 Apple M1
    Memory: 85.89 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 17.9.0 - /opt/homebrew/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.5.5 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 104.0.5112.79
    Firefox: 96.0
    Safari: 15.6
    Safari Technology Preview: 16.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/adapter-static: ^1.0.0-next.39 => 1.0.0-next.39 
    @sveltejs/kit: 1.0.0-next.408 => 1.0.0-next.408 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.7

Severity

blocking an upgrade

Additional Information

Worked fine prior to 1.0.0-next.405.

@heikkilamarko
Copy link

We faced the same problem after migrating our SvelteKit SPA app to 1.0.0-next.410

Screenshot 2022-08-16 at 14 26 48

Rich-Harris added a commit that referenced this issue Aug 16, 2022
* [fix] Lazy load Svelte components to reenable no-ssr use cases

Fixes #5909

* fix order of operations

* lint

Co-authored-by: Rich Harris <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants