question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`$app/environment.browser` isn't reliable for libraries (packaging)

See original GitHub issue

Describe the bug

Every Svelte UI library that want to check if the current environment is the server or the client, uses often the variable $app/environment.browser. While it’s the recommended way for SvelteKit normal application, this is problematic when the library do svelte-kit package, to get the library compiled output.

Any project using a UI library that written in SvelteKit, exported via svelte-kit package, and use the browser variable, will fail to be used in Svelte projects that are outside the SvelteKit environment (e.g. in REPL), since the output still use the browser variable, and wait for the environment to compile it.

There are two possible solutions:

  1. Put the browser variable as part of the specific Svelte environment, instead of the specific SvelteKit environment. (Recommended)
  2. When compiled via svelte-kit package, define the value of browser to be equal to typeof window !== 'undefined'.

Sadly, I’ve seen too many libraries do this mistake, and proposed them to use typeof window !== 'undefined' instead. However, the logic and the sanity are on their side 😃

Reproduction

Just use the browser definition, export via svelte-kit package and see the output isn’t compiled at all, the browser stays in the output.

Logs

No response

System Info

N/A

Severity

annoyance

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
TorstenDittmanncommented, Aug 16, 2022

Not sure if related, but after upgrading to kit version next.409, I’ve been running into following issues with vitetest.

Bildschirmfoto 2022-08-16 um 11 41 46
1reaction
benmccanncommented, Dec 10, 2022

Closing in favor of https://github.com/sveltejs/kit/issues/8033. Please see the recommended solution there

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variables and app settings in Azure App Service
Describes the commonly used environment variables, and which ones can be modified with app settings.
Read more >
Choose an App Engine environment - Google Cloud
When to choose the flexible environment. Application instances run within Docker containers on Compute Engine virtual machines (VM). Applications that receive ...
Read more >
Environment Variables: What They Are and How To Use Them
One of the most common uses of a system environment variable is setting up a PATH variable to a global package/library to be...
Read more >
Android Studio : Missing Strip Tool - Stack Overflow
Unable to strip library 'lib.so' due to missing strip tool for ABI 'ARMEABI'. Packaging it as is. Please help me on how to...
Read more >
Getting Started - Blazor UI Components Library
Create a new Blazor App. To start building .NET apps, download and install the .NET SDK (Software Development Kit). Check everything installed correctly....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found