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.

How to define global variables?

See original GitHub issue

I have a svelte component rendered within another app. That app defines some global variables which I’d like to use.

Whenever I use a custom variable (like config) I get a warning:

(!) Plugin svelte: 'config' is not defined
src/Customize.svelte
41: 
42: <svelte:head>
43:   <link rel="stylesheet" href={`${config.relative_path}/styles.css`} />
                                      ^
44: </svelte:head>
45: 

I cannot, for the life of me, find a way to add known global variables to avoid the warning.

I know I could provide onwarn but that seems hacky and would suppress warnings for actual issues.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pitajcommented, Feb 22, 2021

To be clear, I came into this thinking I had just missed something. Yes this would be a feature request, and probably one to actually apply to the svelte compiler, not the rollup plugin. I understand that the code I gave is currently the suggested solution, but given that many other tools (typescript, eslint, etc) have this ability, it isn’t ideal for supporting global vars.

I’ll close this because rollup global imports is probably a better solution, and because this feature would need to be implemented in the svelte compiler. At least other people will now have an answer if they go looking.

0reactions
lukeedcommented, Feb 22, 2021

I believe the term you’re looking for is “feature request”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python - Global Variables - W3Schools
Variables that are created outside of a function (as in all of the examples above) are known as global variables. Global variables can...
Read more >
Global Variable in Python With Examples [Updated] | Simplilearn
A global variable in Python means having a scope throughout the program. Understand how to create and access global variables with examples.
Read more >
Declare global variables - IBM
A global variable has its value stored in memory and is available to other SPL routines, run by the same user session, on...
Read more >
Global Variables in C - GeeksforGeeks
The global variables get defined outside any function- usually at the very beginning/top of a program. After this, the variables hold their ...
Read more >
Python Global Variables – How to Define a ... - freeCodeCamp
How to Create Variables With Global Scope in Python ... When you define a variable outside a function, like at the top of...
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