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

Issue #968 Fix #1055

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Issue #968 Fix #1055

wants to merge 2 commits into from

Conversation

SinisterMinister
Copy link
Contributor

Fixes #968 by preventing code that's pulled in via b.require() to be considered the standalone module.

This breaks exposing a file added with b.require as the standalone module!

a.js

module.exports = "foo";

Browserify Command

$ browserify --standalone a --require ./a.js:a

Browserify Output

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.a=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"a":[function(require,module,exports){
module.exports = "foo";
},{}]},{},[])(undefined)
});

When this code is run, it will throw a MODULE_NOT_FOUND exception as it tries to export the undefined module.

@jmm
Copy link
Collaborator

jmm commented Mar 17, 2015

@SinisterMinister I appreciate your effort on this. I'm not sure this is going to be the right fix though. For one thing, I have a PR on browser-pack to add the ability to create a standalone bundle and expose a require() at the same time, e.g.:

bundler.js

browserify({standalone: 'whatever'})
  .require('entry', {expose: 'whatever'});

index.html

<script src="bundle.js"><script>
<script>
// true
window.whatever === require('whatever');
</script>

But in any case, the example browserify command you gave should produce a working bundle shouldn't it? And your PR makes it produce a broken bundle?

@pspeter3
Copy link

pspeter3 commented Oct 7, 2015

What's the status on this or the other fix?

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

Successfully merging this pull request may close these issues.

Problem with standalone/require options
3 participants