Skip to content

Dynamic import() drops its second options argument #1473

Open

Description

@trackoor

Expected Behavior

Obfuscating a dynamic import() call with a second options argument (such as { with: { type: "json" } }) should preserve the second argument in the generated output:

import('./data.json', {
    'with': {
        'type': 'json'
    }
});

Current Behavior

Obfuscating a dynamic import() that passes a second options argument parses without error since #1276 was resolved, but drops the second argument from the generated output:

import('./data.json');

This causes JSON or CSS module imports to fail at runtime with ERR_IMPORT_ATTRIBUTE_MISSING.

Steps to Reproduce

  1. Pass import("./data.json", { with: { type: "json" } }); to JavaScriptObfuscator.obfuscate.
  2. Inspect the output returned by .getObfuscatedCode().
  3. Observe that the second options argument { with: { type: "json" } } is missing from the generated import() expression.

JavaScript Obfuscator Edition

  • JavaScript Obfuscator Open Source

Your Environment

  • Obfuscator version used: 5.10.0
  • Node version used: v24.14.1

Stack trace

N/A (no exception during obfuscation; at runtime in Node.js, importing a JSON module without attributes throws TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "./data.json" needs an import attribute of "type: json").

Minimal working example that will help to reproduce issue

const JavaScriptObfuscator = require("javascript-obfuscator");

const code = `import("./data.json", { with: { type: "json" } });`;

console.log(
  JavaScriptObfuscator.obfuscate(code, {
    stringArray: false,
    compact: false,
  }).getObfuscatedCode()
);

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions