Skip to content

Commit 59bc1a1

Browse files
authored
fix(webpack): disable __dirname & __filename webpack polyfills for esm builds (#11146)
1 parent 4eef8b6 commit 59bc1a1

File tree

1 file changed

+9
-0
lines changed
  • packages/webpack5/src/configuration

1 file changed

+9
-0
lines changed

packages/webpack5/src/configuration/base.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
267267
if (env === null || env === void 0 ? void 0 : env.uniqueBundle) {
268268
config.output.filename(`[name].${env.uniqueBundle}.mjs`);
269269
}
270+
// Prevent webpack from generating Node-style ESM shims for __dirname/__filename.
271+
// For output modules, webpack defaults these to a fileURLToPath(import.meta.url) helper
272+
// imported from bare "url", which does not match the NativeScript iOS runtime contract.
273+
// The runtime already provides import.meta.dirname and initializes global.__dirname,
274+
// so webpack's helper is redundant and can misresolve in bundle/worker contexts.
275+
// ESM app or dependency code should use import.meta.dirname/import.meta.url instead
276+
// of expecting webpack to synthesize __dirname/__filename.
277+
config.node.set('__dirname', false);
278+
config.node.set('__filename', false);
270279
}
271280

272281
config.watchOptions({

0 commit comments

Comments
 (0)