You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have project that is configured to build as an IIFE but is creating variables outside the actual IIFE.
This only happens if:
You are accessing a nested field within a global variable using optional chaining
a. ie randomGlobal.randomFieldDepth1?.randomFieldDepth2
b. optionally chaining root object works, randomGlobal?.randomFieldDepth1.randomFieldDepth2
Have a class that defines a field
a. ie class bad { needsAFieldForSomeReason = 42; }
b. removing the field works, class bad { }
c. there might be other aspects to classes that trigger this, but this works for reproduction
Additionally I couldn't determine the correct options to replicate in esbuild, but here's an attempt, with all code encapsulated within the IIFE so might not be an esbuild problem(?).
In my specific case, the 2nd condition to repro is a given, the class is being declared deep in the dependency chain so I can't do anything about that. Where I'm introducing the bug is the 1st condition, optionally accessing a value from the window (a global). There is a workaround currently which is to just, ironically, use an IIFE to return the value. ie:
I should add, I have other apps that meet the above repro requirements, but dont exhibit the bug. much easier to prune to find a bug, then find out why a bug isnt happening
Describe the bug
I have project that is configured to build as an IIFE but is creating variables outside the actual IIFE.
This only happens if:
a. ie
randomGlobal.randomFieldDepth1?.randomFieldDepth2
b. optionally chaining root object works,
randomGlobal?.randomFieldDepth1.randomFieldDepth2
a. ie
class bad { needsAFieldForSomeReason = 42; }
b. removing the field works,
class bad { }
c. there might be other aspects to classes that trigger this, but this works for reproduction
Here is the config:
Additionally I couldn't determine the correct options to replicate in esbuild, but here's an attempt, with all code encapsulated within the IIFE so might not be an esbuild problem(?).
In my specific case, the 2nd condition to repro is a given, the class is being declared deep in the dependency chain so I can't do anything about that. Where I'm introducing the bug is the 1st condition, optionally accessing a value from the window (a global). There is a workaround currently which is to just, ironically, use an IIFE to return the value. ie:
It seems likely to be related to:
#11641 but this bug has the added caveat of the first condition.
Not sure if related to the following:
#14537
#14094
Excited to hear y'all's thoughts, thank you in advance.
Reproduction
https://stackblitz.com/edit/vitejs-vite-prc1zp?file=dist%2Fvite-starter.iife.js,main.js,index.html&terminal=dev
Steps to reproduce
npm run build
dist
folder has declared vars outside the IIFESystem Info
From StackBlitz fyi System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.18.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm pnpm: 8.9.2 - /usr/local/bin/pnpm npmPackages: vite: ^4.4.8 => 4.5.0
Used Package Manager
npm
Logs
Click to expand!
The text was updated successfully, but these errors were encountered: