Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Some wrapper checks for require will not export as expected #38

@leeyeh

Description

@leeyeh

I'm trying to rollup protobufjs with rollup-plugin-commonjs, but I get undefined as export. It turns out the UMD wrapper of protobufjs will check the type of require to export the module as commonjs.

(function(global, factory) {
    /* AMD */ if (typeof define === 'function' && define["amd"])
        define(["bytebuffer"], factory);
    /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
        module["exports"] = factory(require("bytebuffer"), true);
    /* Global */ else
        (global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
})(this, function(ByteBuffer, isCommonJS) {
  // factory
})

The specs of Commonjs defines require as a Function. It make sense for wrapper to check for it. Currently, I use a plugin to add require as a noop function since it should never been called anyway. I hope rollup-plugin-commonjs can handle such use case more elegantly.

function () {
    return {
      intro() {
        return 
           `var require = require || function(id) {throw new Error('Unexpected required ' + id)};`;
      }
    };
  };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions