#4505·esbuild

In IIFE mode, the inserted "use strict" statement should be inside the function

Author: jsnajdrCreated Aug 4, 2026Updated Aug 25, 2026

When esbuild creates an iife bundle and for some reason it inserts "use strict" -- when it's in the entrypoint file, when triggered by tsconfig.json strict or alwaysStrict option -- the "use strict" statement should be inside the IIFE function:

javascript
// expected state
(() => {
  "use strict";
  // code
})();

The actual behavior is that it's outside, on the top-level:

javascript
// bad state
"use strict";
(() => {
  // code
})();

The reason is that some platforms (e.g., WordPress) optionally concatenate scripts together, and then the use strict statement leaks into other scripts that follow. It's better when the strict mode is explicitly scoped.