Skip to content

femanager.min.js breaks if bundled because not valid ESM code #706

Description

@Make66

[PARSE_ERROR] Error: Cannot assign to 'arguments' in strict mode

  • in vendor/in2code/femanager/Resources/Public/JavaScript/Femanager.min.js at 658..667

Vite re-bundles it as ESM, which is always strict mode by spec.
So lets fix it: arguments is used as a local variable but also appears as a string literal in r.match("arguments") — so a blanket replace would break that. Lets use targeted replacements for each non-string occurrence.
Snippet from my vite.config.ts that documents the patch-on-the-fly needed:

        // 'arguments' is reserved in strict mode; rename the local variable usages
        // (keep the string literal r.match("arguments") untouched)
        return code
          .replace('arguments=JSON.parse', '_args=JSON.parse')
          .replace('for(var r in arguments)', 'for(let r in _args)')
          .replace('arguments.hasOwnProperty(r)', '_args.hasOwnProperty(r)')
          .replace('arguments[r]', '_args[r]');

The final config now patches both files surgically — replacing only the variable references to arguments, leaving the r.match("arguments") string literal intact.
Sorry for not offering a pull request, but in the package, there is only the dist version of Femanager.js, not the src version

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