-
Notifications
You must be signed in to change notification settings - Fork 116
Bundled dependencies built with browserify broken #77
Comments
I managed to set up a minimal reproduction case for this, check it out at rollup-plugin-commonjs-repro77. Basically, the bundled code breaks on any CommonJS module built with Browserify that exports itself as a UMD module. This is exports.foo = function () {
return 42;
}; which is built with:
The The resulting import vendor from '../vendor/dist';
export function bar() {
return vendor.foo() + 1;
} Once again, in practice I would use The rollup -c -o dist/index.js with the following rollup configuration: {
entry: 'src/index.js',
format: 'iife',
moduleName: 'repro77',
plugins: [
commonjs({
include: 'vendor/**'
})
]
} The resulting |
@MattiasBuelens thanks a lot :) Spent about 2 hours today trying to figure what was wrong with those magic lines: inside |
While waiting for a fix, I have a (really dirty) workaround for this. The problem is that the browserify code tries to access a non-existing {
plugins: [
nodeResolve(),
commonjs({
include: 'node_modules/**'
}),
{
intro: function() {
return 'var require;';
}
}
]
} This makes the if (typeof require === 'function') {
var fs = require('fs'); // undefined is not a function
} It's good enough for my use case though. 😛 In the meantime, any ideas on how this should be fixed "properly"? What should this plugin do with browserify dependencies? |
fix typeof require === "function" && require
Fixed (properly) in 5.0.2, sorry for the wait! |
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 theirdist/video.js
has aumd
wrapper around browserify'sbrowser-pack
prelude: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:
foo.js
and bundle it with browserify. (In practice, we'd get the bundledfoo.js
from an npm dependency.)bar.js
thatimport
s from the builtfoo.js
and bundle it with rollup.bar.js
inside a browser.The text was updated successfully, but these errors were encountered: