I am new to Vite and want just one simple thing -> to reference a variable in my DOM that i declared in the main.js.
https://stackblitz.com/edit/vitejs-vite-urotp2?file=main.js,index.html,counter.js&terminal=dev
I searched the Internet for 2 Days now:/
Is this even possible or am I missing something here?
Thankfull for any help.
#Variable Scope issue
1 messages · Page 1 of 1 (latest)
Variables in ESM modules are scoped to the modules, you can only access them in other modules by exporting them and using import in the other module, like you did for the counter.
More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
If you want to bypass this, you can always set something on window object to make it global, but that should be used only exceptionally