js-confuser icon indicating copy to clipboard operation
js-confuser copied to clipboard

Uncaught SyntaxError: Cannot use 'import.meta' outside a module

Open meydaikey opened this issue 11 months ago • 1 comments

Config:

{
  target: 'browser',
  preset: undefined,
  pack: true,
}

Code:

console.log(import.meta.url)

Expected behavior

prints module url to console

Actual behavior

syntax error because pack: true makes the code be outside a module

meydaikey avatar Dec 11 '24 21:12 meydaikey

Pack does not support full module features yet.

For now store import.meta into global variable, and modify the obfuscated output:

// Input.js
console.log(importMeta.url);

// Output.js
var importMeta = import.meta; // <- Add this manually
Function("rZK8Uq","return console[\"log\"](rZK8Uq[\"KRBtQm\"][\"url\"]);")({get"KRBtQm"(){return importMeta}});

MichaelXF avatar Dec 11 '24 23:12 MichaelXF