diff --git a/src/Bundler.js b/src/Bundler.js index f6bbd204c86..f1901b41cd8 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -607,6 +607,12 @@ class Bundler extends EventEmitter { } } + // Skip this asset if it's already in the bundle. + // Happens when circular dependencies are placed in an isolated bundle (e.g. a worker). + if (bundle.isolated && bundle.assets.has(asset)) { + return; + } + let isEntryAsset = asset.parentBundle && asset.parentBundle.entryAsset === asset; diff --git a/test/integration/worker-circular/index.js b/test/integration/worker-circular/index.js new file mode 100644 index 00000000000..c25bcacc792 --- /dev/null +++ b/test/integration/worker-circular/index.js @@ -0,0 +1 @@ +new Worker('worker.js'); diff --git a/test/integration/worker-circular/worker-dep.js b/test/integration/worker-circular/worker-dep.js new file mode 100644 index 00000000000..d0a1ee54a41 --- /dev/null +++ b/test/integration/worker-circular/worker-dep.js @@ -0,0 +1 @@ +require('./worker'); diff --git a/test/integration/worker-circular/worker.js b/test/integration/worker-circular/worker.js new file mode 100644 index 00000000000..13c8b199241 --- /dev/null +++ b/test/integration/worker-circular/worker.js @@ -0,0 +1 @@ +require('./worker-dep'); diff --git a/test/javascript.js b/test/javascript.js index 65a2fb36bce..182d3da86a1 100644 --- a/test/javascript.js +++ b/test/javascript.js @@ -250,6 +250,22 @@ describe('javascript', function() { }); }); + it('should support bundling workers with circular dependencies', async function() { + let b = await bundle(__dirname + '/integration/worker-circular/index.js', { + sourceMaps: false + }); + + await assertBundleTree(b, { + name: 'index.js', + assets: ['index.js'], + childBundles: [ + { + assets: ['worker.js', 'worker-dep.js'] + } + ] + }); + }); + it('should dynamic import files which import raw files', async function() { let b = await bundle( __dirname + '/integration/dynamic-references-raw/index.js'