Skip to content

RequireJS environment in browser will break the UMD module conversion #5900

@pakholeung37

Description

@pakholeung37

Describe the bug

Say I have an umd module

;(function(root, factory) {
    // istanbul ignore next
    if (typeof define === "function" && define.amd) {
        // istanbul ignore next
        define([], factory)
    } else if (typeof module === "object" && module.exports) {
        module.exports = factory()
    } else {
        // istanbul ignore next
        root.regexpToAst = factory()
    }
})(
    typeof self !== "undefined"
        ? // istanbul ignore next
          self
        : this,
    function() {}
)

With the commonjs conversion, it returns code like

var require_regexp_to_ast = __commonJS({
  "../../node_modules/regexp-to-ast/lib/regexp-to-ast.js"(exports, module) {
    (function(root, factory) {
      if (typeof define === "function" && define.amd) {
        define([], factory);
      } else if (typeof module === "object" && module.exports) {
        module.exports = factory();
      } else {
        root.regexpToAst = factory();
      }
    })(typeof self !== "undefined" ? self : exports, function() {
      function RegExpParser2() {
      }

But this will break in runtime because there is global define in the browser since I have a requireJS environment. This module will be registered in the global AMD module instead of vite ESM module.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    has workaroundp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions