Simple browserify test only runs when built with --debug

55 views Asked by At

I have a simple hello world script main.js:

window.addEventListener('load', function() {
    "use strict";
    document.getElementById('output').textContent = "Hello, browser.";
});

If I build bundle.js with:

browserify -r ./main.js > bundle.js

It doesn't run in the browser. No errors, just doesn't execute. If I use:

browserify -r --debug ./main.js > bundle.js

It runs fine. Why doesn't the non-debug one run?

1

There are 1 answers

1
marcel On BEST ANSWER

-r means require. -> -r file.js means, that you will put it into a seperate scope to require it in an other bundle, but it don't will execute.

Your "solution" -r --debug (or short -r -d) works, because the require attribute has no parameter/file, so it will be ignored by browserify.

Just removing -r --debug should solve your problem.

This...

browserify -r --debug ./main.js -o ./bundle.js

...is the same as this:

browserify -d ./main.js -o ./bundle.js