browserify / browserify/browserify

Bug: Resultant bundles fail to find modules via require() as expected. Example code inside

Open
#1,862 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.7k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Expected Result
1. A valid bundle is included and all modules can be found via require()

### Actual result
The bundle fails to require the "bluebird" module with the following error:

> Uncaught Error: Cannot find module 'bluebird'

You can see in the reproduction code that bluebird does in fact exist. It is defined in main2.js/bundle2.js. As a result, it should be found, but it fails to be found.

The issue is that when a bundle uses "external" it fails to look for the module in another bundle (the "external" code that includes it), which defeats the point of externally including something.

### Reproduction Code

Include bundle1.js and bundle2.js into a file and then call the functions:

```
window.main1();
window.main2();
```
You will receive the error that bluebird cannot be found even though it is clearly defined in main2/bundle2

It is the main1() function that fails to find the module.

Grunt file

```
module.exports = function(grunt) {
grunt.initConfig({
browserify: {
main1: {
src: ['src/main1.js'],
dest: 'build/bundle1.js',
options: {
external: ['bluebird']
},
},

main2: {
src: ['src/main2.js'],
dest: 'build/bundle2.js',
}
}
});

grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', ['browserify']);

};
```

Main1.js

```
window.main1 = function() {
let pexec = require('pexec');
console.log(pexec);
}
```

Main2.js

```
window.main2 = function() {
let t = require('bluebird');
console.log(t);
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.