Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when used with factor-bundle with somewhat specific source files layout #28

Closed
futpib opened this issue Oct 27, 2016 · 2 comments

Comments

@futpib
Copy link

futpib commented Oct 27, 2016

After building my project with require-globify and factor-bundle I get the following exception in the browser:

a.js:6 Uncaught TypeError: Cannot read property '0' of undefined
    at Object.require.4.dup (file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:6:16)
    at s (file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:1:262)
    at file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:1:313
    at Object.require.3../lib/util.js (file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:2:27)
    at s (file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:1:262)
    at e (file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:1:433)
    at file:///home/futpib/tmp/require-globify-factor-bundle-issue-demo/dist/a.js:1:451

Steps to reproduce:

  1. clone https://github.com/futpib/require-globify-factor-bundle-issue-demo.git
  2. npm install
  3. node index.js
  4. xdg-open index.html or open index.html in your browser
  5. uncaught exception in the browser console

I tried to come up with a shorter executable example, but this is the simplest I could get.

Here is the compiled code that leads to exception (prettified by chrome's debugger):

<!-- index.html -->
<script src="./dist/common.js"></script>
<script src="./dist/a.js"></script>
// common.js
require = (/* omitting boilerplate browser-pack/prelude.js */)({
    2: [function(require, module, exports) {}
    , {}]
}, {}, [])
// a.js
require = (/* omitting boilerplate browser-pack/prelude.js */)({
    3: [function(require, module, exports) {
        module.exports = {
            'util': require('./lib/util.js')
        };
    }
    , {
        "./lib/util.js": 4
    }],
    4: [function(require, module, exports) {
        arguments[4][2][0].apply(exports, arguments) // Uncaught TypeError: Cannot read property '0' of undefined
    }
    , {
        "dup": 2
    }]
}, {}, [3])

Note that naming of the src/* subdirectories is somehow significant (a and a-b). If I rename a-b to b or ab I am no longer able to reproduce this. (no idea)

Also, identical contents of src/a/lib/util.js and src/a-b/lib/util.js seems to be significant (they don't have to be empty, but they have to be identical, for this issue to reproduce). This makes me thing this may be related to dedupe part of browserify pipeline, but I'm not yet that deep into the whole build process to figure this one out for sure.

Workaround: don't glob-require identical files within directories that are prefixes of one another :).

I know this is a very specific edge case that no one probably cares about, I hope to at least get some pointers to what this could be related to.

@futpib futpib changed the title Issue when used with factor-bundle with somewhat specific source files layout Exception when used with factor-bundle with somewhat specific source files layout Oct 27, 2016
@futpib
Copy link
Author

futpib commented Oct 28, 2016

This turned out to be unrelated to require-globify. Sorry for that.

@futpib futpib closed this as completed Oct 28, 2016
@futpib
Copy link
Author

futpib commented Oct 28, 2016

This is a duplicate of browserify/factor-bundle#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant