Reproduction link or steps
Reproduction Link - REPL link
Hi Team,
As you can see in the REPL link, import.meta.url, which is used in the createRequire function, is left in the output even though createRequire itself is not used and gets removed by Rolldown / Oxc.
This seems unexpected because the input file is empty, but the output still contains a standalone import.meta.url.
What is expected?
The expected output should be like the below one
import "node:module";
//#endregion
export {};
What is actually happening?
I think this is happening because, as mentioned in the Oxc docs, only the function call is treated as pure, not its arguments.
So in a helper like this:
export var __require = /* @__PURE__ */ createRequire(import.meta.url);
createRequire(...) can be removed, but the argument import.meta.url may still be preserved.
Using a pure IIFE seems to solve the issue, as mentioned in the Oxc docs:
export var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
This way, the whole expression, including import.meta.url, can be removed when the helper is unused.
System Info
System:
OS: Windows 11 10.0.26200
CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-13500H
Memory: 1.54 GB / 15.75 GB
Binaries:
Node: 24.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - C:\Users\96110\AppData\Roaming\npm\yarn.CMD
npm: 11.13.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 11.4.0 - C:\Users\96110\AppData\Local\pnpm\bin\pnpm.CMD
Browsers:
Chrome: 149.0.7827.114
Edge: Chromium (149.0.4022.69)
Internet Explorer: 11.0.26100.8115
npmPackages:
rolldown: workspace:* => 1.1.1
Any additional comments?
No response
Reproduction link or steps
Reproduction Link - REPL link
Hi Team,
As you can see in the REPL link,
import.meta.url, which is used in thecreateRequirefunction, is left in the output even thoughcreateRequireitself is not used and gets removed by Rolldown / Oxc.This seems unexpected because the input file is empty, but the output still contains a standalone
import.meta.url.What is expected?
The expected output should be like the below one
What is actually happening?
I think this is happening because, as mentioned in the Oxc docs, only the function call is treated as pure, not its arguments.
So in a helper like this:
export var __require = /* @__PURE__ */ createRequire(import.meta.url);createRequire(...) can be removed, but the argument import.meta.url may still be preserved.
Using a pure IIFE seems to solve the issue, as mentioned in the Oxc docs:
export var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();This way, the whole expression, including import.meta.url, can be removed when the helper is unused.
System Info
System: OS: Windows 11 10.0.26200 CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-13500H Memory: 1.54 GB / 15.75 GB Binaries: Node: 24.16.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.22 - C:\Users\96110\AppData\Roaming\npm\yarn.CMD npm: 11.13.0 - C:\Program Files\nodejs\npm.CMD pnpm: 11.4.0 - C:\Users\96110\AppData\Local\pnpm\bin\pnpm.CMD Browsers: Chrome: 149.0.7827.114 Edge: Chromium (149.0.4022.69) Internet Explorer: 11.0.26100.8115 npmPackages: rolldown: workspace:* => 1.1.1Any additional comments?
No response