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.

Bundled dependencies built with browserify broken #77

@MattiasBuelens

Description

@MattiasBuelens

The newest version (3.1.0) broke some of my dependencies.

For example, I bundle video.js which is built with grunt-browserify. The first line of their dist/video.js has a umd wrapper around browserify's browser-pack prelude:

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.videojs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

There are two problematic lines in the browser-pack prelude:

  • var a=typeof require=="function"&&require;
  • var i=typeof require=="function"&&require;

Version 3.1.0 of this plugin transforms these lines into:

  • var a='function'=="function"&&require;
  • var i='function'=="function"&&require;

This breaks the code at run time inside a browser with strict mode enabled, since there's no global require function.

For now, I've pinned my version of rollup-plugin-commonjs to =3.0.2, so that my builds keep working.

I have not yet found the time to set up a full reproduction case, but this is the general idea:

  1. Create foo.js and bundle it with browserify. (In practice, we'd get the bundled foo.js from an npm dependency.)
  2. Create bar.js that imports from the built foo.js and bundle it with rollup.
  3. Load bar.js inside a browser.

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