GithubHelp home page GithubHelp logo

browserify-shim's Introduction

browserify-shim build status

Make CommonJS-Incompatible Files Browserifyable

package.json

{
  "main": "./js/entry.js",
  "browser": {
    "jquery": "./js/vendor/jquery.js"
  },
  "browserify-shim": {
    "jquery": "$",
    "three": "global:THREE"
  },
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "dependencies": {
    "browserify-shim": "~3.2.0"
  }
}
browserify . -d -o bundle.js

Table of Contents generated with DocToc

Installation

npm install browserify browserify-shim

For a version compatible with [email protected] run npm install [email protected] instead.

For a version compatible with the v2 API npm install [email protected] instead.

Features

The core features of browserify-shim are:

  • Shims non-CommonJS modules in order for them to be browserified by specifying an alias, the path to the file, and the identifier under which the module attaches itself to the global window object.
  • Includes depends for shimming libraries that depend on other libraries being in the global namespace.
  • applies shims configured inside the dependencies of your package

Additionally, it handles the following real-world edge cases:

  • Modules that just declare a var foo = ... on the script level and assume it gets attached to the window object. Since the only way they will ever be run is in the global context โ€” "ahem, โ€ฆ NO?!"
  • Makes define and also module be undefined, in order to fix improperly-authored libraries that need shimming but try anyway to use AMD or CommonJS. For more info read the comment inside this fixture
  • removes invalid requires, i.e. require('jquery') although 'jquery' isn't installed due to the library being improperly published or installed incorrectly via a downloader like bower

Since browserify-shim is a proper browserify transform you can publish packages with files that need to be shimmed, granted that you specify the shim config inside the package.json.

When browserify resolves your package it will run the browserify-shim transform and thus shim what's necessary when generating the bundle.

browserify-shim walks upwards from each source file and uses the first "browserify-shim" configuration it finds in a package.json file. You can't shim files outside your project from your project's package. You can add multiple package.json files as long as browserify-shim can always find a package above each source file with the right configuration.

API

You Will Always

1. Install browserify-shim dependency

In most cases you want to install it as a devDependency via:

npm install -D browserify-shim

2. Register browserify-shim as a transform with browserify

Inside package.json add:

{ 
  "browserify": {
    "transform": [ "browserify-shim" ]
  }
}

Browserify transforms are run in order and may modify your source code along the way. You'll typically want to include browserify-shim last.

3. Provide browserify-shim config

Inside package.json add:

{
  "browserify-shim": {
    "./js/vendor/jquery.js": "$",
    "three": "global:THREE"
  }
}

The above includes ./js/vendor/jquery.js (relative to the package.json) in the bundle and exports window.$.

Additionally it exposes window.THREE as three, so you can var three = require('three'). More info below.

Short Form vs. Long Form config

Since jquery does not depend on other shimmed modules and thus has no depends field, we used the short form to specify its exports, however the example above is equivalent to:

{
  "browserify-shim": {
    "./js/vendor/jquery.js": { "exports": "$" }
  }
}

You will sometimes

a) Expose global variables via global:*

In some cases the libraries you are using are very large and you'd prefer to add them via a script tag instead to get the following benefits:

  • faster bundling times since the library is not included in the bundle
  • pull libraries from a CDN which allows it to be pulled straight from the user's browser cache in case it was downloaded before

We'll show how this works by taking the rather huge yet awesome THREE.js library as an example:

1. add script tag for library you want to expose
<!-- index.html -->
<head>
  <meta charset=utf-8 />
  <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r61/three.min.js"></script>
</head>
2. Add expose global config to package.json
{
  "browserify-shim": {
    "three": "global:THREE"
  }
}
2.a. Add expose global config to external shim config

In case you are using an external shim config, you may achieve the same by specifying the global via an exports.

module.exports = {
  'three': { exports: 'global:THREE' }
}

more about external configs here

Note: THREE.js attaches window.THREE.

3. Require library by the name it was exposed as
var THREE = require('three');
Why not just var THREE = window.THREE?

You want to avoid spreading the knowledge that THREE is a global and stay consistent in how you resolve dependencies. Additionally if THREE would ever be published to npm and you decide to install it from there, you don't have to change any of your code since it already is requireing it properly.

b) Use aliases

You may expose files under a different name via the browser field and refer to them under that alias in the shim config:

{
  "browser": {
    "jquery": "./js/vendor/jquery.js"
  },
  "browserify-shim": {
    "jquery": "$"
  }
}

This also allows you to require this module under the alias, i.e.: var $ = require('jquery').

c) Provide an external shim config

{
  "browserify-shim": "./config/shim.js"
}

The external shim format is very similar to the way in which the shim is specified inside the package.json. See below for more details.

d) Diagnose what browserify-shim is doing

You may encounter problems when your shim config isn't properly setup. In that case you can diagnose them via the BROWSERIFYSHIM_DIAGNOSTICS flag.

Simply set the flag when building your bundle, i.e.:

BROWSERIFYSHIM_DIAGNOSTICS=1 browserify -d . -o js/bundle.js

or in a build.js script add: process.env.BROWSERIFYSHIM_DIAGNOSTICS=1 to the top.

Multi Shim Example including dependencies

Some libraries depend on other libraries to have attached their exports to the window for historical reasons :(. (Hopefully soon we can truly say that this bad design is history.)

In this contrived example we are shimming four libraries since none of them are commonJS compatible:

  • x exports window.$
  • x-ui exports nothing since it just attaches itself to x. Therefore x-ui depends on x.
  • y exports window.Y and also depends on x expecting to find it on the window as $.
  • z exports window.zorro and depends on x and y. It expects to find x on the window as $, but y on the window as YNOT, which is actually different than the name under which y exports itself.

We will be using the depends field in order to ensure that a dependency is included and initialized before a library that depends on it is initialized.

Below are three examples, each showing a way to properly shim the above mentioned modules.

a) Config inside package.json without aliases

{
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "browserify-shim": {
    "./vendor/x.js"    :  "$",
    "./vendor/x-ui.js" :  { "depends": [ "./vendor/x.js" ] },
    "./vendor/y.js"    :  { "exports": "Y", "depends": [ "./vendor/x.js:$" ] },
    "./vendor/z.js"    :  { "exports": "zorro", "depends": [ "./vendor/x.js:$", "./vendor/y.js:YNOT" ] }
  }
}

Note: the depends array consists of entries of the format path-to-file:export

b) Config inside package.json with aliases

{
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "browser": {
    "x"    :  "./vendor/x.js",
    "x-ui" :  "./vendor/x-ui.js",
    "y"    :  "./vendor/y.js",
    "z"    :  "./vendor/z.js"
  },
   "browserify-shim": {
    "x"    :  "$",
    "x-ui" :  { "depends": [ "x" ] },
    "y"    :  { "exports": "Y", "depends": [ "x:$" ] },
    "z"    :  { "exports": "zorro", "depends": [ "x:$", "y:YNOT" ] }
  }
}

Note: the depends entries make use of the aliases as well alias:export

c) Config inside ./config/shim.js without aliases

package.json

{
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "browserify-shim": "./config/shim.js"
}

shim.js

module.exports = {
  '../vendor/x.js'    :  { 'exports': '$' },
  '../vendor/x-ui.js' :  { 'depends': { '../vendor/x.js': null } },
  '../vendor/y.js'    :  { 'exports': 'Y', 'depends': { '../vendor/x.js': '$' } },
  '../vendor/z.js'    :  { 'exports': 'zorro', 'depends': { '../vendor/x.js': '$', '../vendor/y.js': 'YNOT' } }
}

Note: all paths are relative to ./config/shim.js instead of the package.json.

The main difference to a) is the depends field specification. Instead it being an array of strings it expresses its dependencies as a hashmap:

  • key: path-to-file
  • value: the name under which it is expected to be attached on the window

More Examples

browserify-shim's People

Contributors

aearly avatar anselmbradford avatar bendrucker avatar bitdeli-chef avatar creepone avatar danielbaird avatar danielmoore avatar dependabot[bot] avatar domenic avatar mreinstein avatar patrickcjh avatar paulmelnikow avatar silvenon avatar sobolevn avatar thaiat avatar thlorenz avatar trippnology avatar ttacon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

browserify-shim's Issues

Better syntax for depends

bundle
.use(shim({ alias: 'underscore', path: '...', exports: null }))
.use(shim({
  alias: 'backbone.stickit',
  path: '...',
  exports: null,
  depends: {
    'underscore': '_',
    'backbone': 'Backbone',
    'jquery': 'jQuery'
  }
}));

Aliased globals

I have some popular libs like jquery and lodash that I don't want to include in my browserify bundle to shave off some precious bytes. I know about global:*, but I can't find any info or examples on combining it with an alias so that other shimmed modules can depend on them without specifying the full path each time. What I want is something like this:

{
   ...
  "browser": {
    "jquery": "WHAT-TO-PUT-HERE?",
    ...
  },
  "browserify-shim": {
    "jquery": "global:$",
    ...
    "sidr": {"exports": "$.sidr", "depends": ["jquery"]},
    ""
  }
  ...
}

I haven't gotten this to work so I'm guessing this is not supported atm... Right?

Confused how to add a shim for Thorax

I am confused after reading the docs, how to shim Thorax.

Thorax has a dozen of classes, which in the original project are not bundled: https://github.com/walmartlabs/thorax/tree/master/src

The important files are Thorax, which is based on Backbone and Handlebars. I could do npm install backbone but unsure how to map the Handlebars from Thorax here.

In the first line of the docs, there is a parameter -d which might be nice to add a note what it does. I have just digged intro browserify for some days, and don't know all the options.

The uppercase THREE might be explained too, since this syntax looks special too.

Thanks!

Finding package.json

Hey! I wanted to bounce an idea off you.

browserify-shim and browserify-transform-tools both find the package.json config by starting at the file being transformed and walking up the tree. This potentially runs into a problem if you're using something like debowerify, because you can accidentally pick up the bower package.json, you probably don't want to do (even if it has configuration in it, you probably want to ignore it, since it's probably for building the bower library, and not for including the bower library.)

I was thinking about this tonight, and I think I have a better solution; instead start at process.cwd() and work your way upwards, and stop at the first package.json you find. My thinking is that 99.9% of the time, someone is going to run browserify from some kind of script or build tool that's going to live in the root of the project anyways - makefiles, cakefiles, grunt.js files all typically live in the project root. Maybe someone would write a script and dump it in project/bin or project/build or something, but this covers that case neatly, too. If you want to catch the other 0.1%, you could make your algorithm:

  • If process.env["BROWSERIFY_CONFIG"] is defined, try to require it as your configuration.
  • Else, search for package.json starting at process.cwd().

Thoughts?

Cannot expose Backbone and Underscore properly

I might be the idiot here, but I feel like I've tried to get this working in every way possible before posting this issue

The Goal
Expose jQuery (and $), Backbone, and _ (underscore) on window

  • jQuery is located at ./vendor/jquery-2.1.0.js
  • Backbone is installed via npm (v1.1.0)
  • underscore is an included dependency of Backbone

What I have below works half way, but still leaves an open question for me.

Here's my package.json

"scripts": {
  "build": "browserify -d lib.js > public/js/lib.js",
  "start": "npm run-script build && node index.js"
},
"devDependencies": {
  "backbone": "~1.1.0",
  "browserify": "~3.20.0",
  "browserify-shim": "~3.1.4"
},
"browserify": {
  "transform": [
    "browserify-shim"
  ]
},
"browser": {
  "jquery": "./vendor/jquery-2.1.0.js",
  "backbone": "./node_modules/backbone/backbone.js"
},
"browserify-shim": {
  "jquery": {
    "exports": "$"
  },
  "backbone": {
    "depends": "jquery",
    "exports": "Backbone"
  }
}

Here's my lib.js

var jQuery = require("jquery"),
    Backbone = require("backbone");

console.log("hello");
console.log("jQuery", jQuery);
console.log("$", $);
console.log("jQuery === $", jQuery === $);
console.log("Backbone", Backbone);
console.log("Backbone.$ === jQuery", Backbone.$ === jQuery);

Things that are working

  • the script runs, yay โœ“
  • jQuery logs the proper output โœ“
  • $ logs the proper output โœ“
  • jQuery === $ logs true โœ“
  • Backbone logs the proper output โœ“
  • Backbone.$ === jQuery logs true โœ“
  • _ is undefined โ˜น

Questions I have:

  • Off the bat, I don't feel like I should need to manually specify the module path for backbone in my package.json.

    "browser": {
      "jquery": "./vendor/jquery-2.1.0.js",
      "backbone": "./node_modules/backbone/backbone.js"
    }

    It feels like I'm doing something wrong. Seeing as though I'm able to do a simple require("backbone") in a script, I don't see why this needs additional config here. What's the proper way to expose an npm module?

  • $ and Backbone are only attached to window if I have these lines in lib.js

    var jQuery = require("jquery"),
        Backbone = require("backbone");

    If I leave this lib.js blank, window.$ and window.Backbone will be undefined. Why do I specify them with exports in package.json if that doesn't seem to do anything?

  • How can I export the dependency of another module? I.e., how can I attach backbone's underscore dependency to window._ or alias it so I can do require("underscore") ?


I hope that you can see I've done some homework. I would really appreciate a little assistance on this.

browserify-shim incompatible with other transforms (namely brfs)?

Trying to add brfs to my browserify transforms, ever since the shim moved to package.json config:

"browserify": {
    "transform": [
        "browserify-shim",
        "brfs"
    ]
},

Results in this error every time:

Error: Unable to find a browserify-shim config section in the package.json for C:\My Programs\nodist\bin\node_modules\browserify\lib_empty.js

Results in the same error when attempting to use the transform via the command line using the -t brfs option.

Example for using shim() in gulp task directly

I am struggling with using shim function in my gulpfile.js directly (without using the package.json config).
All the examples I can find are using the shim({...}).require (given below an example ), but when I try to use it with browserify-shim#3.4.1 I get the error Object #<Stream> has no method 'require'.

shim(browserify(), { // jQuery attaches itself to the window as '$' so we assign the exports accordingly jquery: { path: './js/vendor/jquery-1.9.1.min.js', exports: '$' } }) .require(require.resolve('./js/entry.js'), { entry: true })
I am unable to find any example that uses shim in gulp task successfully with latest version of browserify-shim.

Can you please provide an example on how to use shim directly in gulp task using latest version of browserify-shim?

NPM package gets included through browserify despite being shimmed out

When buillding the outfile the package I'm requiring gets included if found before getting replaced with window.packageName. This is possibly because browserify runs before browserify-shim. How can I force browserify-shim to run before browserify so that all require calls get shimmed out before any packages are included?

AngularJS shimming not working with grunt-browserify

I added a shim-angular.js file with the following contents:

'use strict';
/*jshint asi: true*/

var testLib = require('./utils/test-lib')
var test = require('tap').test
  , baseUrl = 'https://raw.github.com/angular/angular.js/master/src/Angular.js'

test('angular', function (t) {
  var shimConfig = { angular: {  exports: 'angular' } }
  t.plan(1)
  testLib(t, { 
      name: 'angular.js'
    , test: function (t, resolved) { t.equals(typeof resolved().init, 'function', 'shims angular') }
    , shimConfig: shimConfig
  })
});

and get this output when running npm test

    Command: "node" "shim-angular.js"
    TAP version 13
    not ok 1 test/shim-angular.js
      ---
        exit:    8
        stderr:  |
          /projects-personal/browserify-shim/test/shim-angular.js:13
              , test: function (t, resolved) { t.equals(typeof resolved().init, 'functio
                                                               ^
          TypeError: undefined is not a function
              at testLib.test (/projects-personal/browserify-shim/test/shim-angular.js:13:54)
              at /projects-personal/browserify-shim/test/utils/test-lib.js:63:9
              at Stream.<anonymous> (/projects-personal/browserify-shim/node_modules/browserify/index.js:141:35)
              at Stream.EventEmitter.emit (events.js:117:20)
              at Stream.handleEnd (/projects-personal/browserify-shim/node_modules/browserify/node_modules/duplexer/index.js:71:21)
              at Stream.EventEmitter.emit (events.js:117:20)
              at drain (/projects-personal/browserify-shim/node_modules/through/index.js:33:23)
              at Stream.stream.queue.stream.push (/projects-personal/browserify-shim/node_modules/through/index.js:41:5)
              at Stream.end (/projects-personal/browserify-shim/node_modules/browserify/index.js:263:14)
              at _end (/projects-personal/browserify-shim/node_modules/through/index.js:61:9)
        command: "node" "shim-angular.js"
      ...

    1..1
    # tests 1
    # fail  1

PS - The impress.js test appears to be failing because it times out. Replacing the URL with https://raw.github.com/bartaz/impress.js/master/js/impress.js however, results in this output:

not ok test/shim-impress.js ............................. 1/2
    Command: "node" "shim-impress.js"
    TAP version 13
    not ok 1 Error: Parsing file /projects-personal/browserify-shim/test/fixtures/shims/impress.js: Line 2: Unexpected token <
      ---
        file:   /projects-personal/browserify-shim/test/utils/test-lib.js
        line:   55
        column: 22
        stack:  
          - getCaller (/projects-personal/browserify-shim/node_modules/tap/lib/tap-assert.js:418:17)
          - assert (/projects-personal/browserify-shim/node_modules/tap/lib/tap-assert.js:21:16)
          - Function.fail (/projects-personal/browserify-shim/node_modules/tap/lib/tap-assert.js:95:10)
          - Test._testAssert [as fail] (/projects-personal/browserify-shim/node_modules/tap/lib/tap-test.js:86:16)
          - Stream.<anonymous> (/projects-personal/browserify-shim/test/utils/test-lib.js:55:22)
          - Stream.EventEmitter.emit (events.js:117:20)
          - Stream.EventEmitter.emit (events.js:117:20)
          - Stream.EventEmitter.emit (events.js:117:20)
          - parseDeps (/projects-personal/browserify-shim/node_modules/browserify/node_modules/module-deps/index.js:105:27)
          - done (/projects-personal/browserify-shim/node_modules/browserify/node_modules/module-deps/index.js:95:13)
      ...
    ok 2 test/shim-impress.js

    1..2
    # tests 2
    # pass  1
    # fail  1

Api in V3

There is a branch with an example on how to use the api in v2. Can the same be done in v3? How?

Absolute Paths being used as shim aliases?

I'm running into a sitution where I have two shimmed bundles like:

"browser": {
  "jquery": "./Scripts/lib/jquery-1.8.2.js",
  "kendo-web": "./Scripts/lib/kendo.web.js",
  "report-viewer": "./Scripts/lib/ReportViewer-8.0.14.225.js"
},
"browserify-shim": {
  "jquery": "$",
  "kendo-web": { "exports": "kendo", "depends": [ "jquery:jQuery"] },
  "report-viewer": {
    "exports": "telerikReportViewer",
    "depends": [
      "jquery:jQuery",
      "kendo-web:kendo"
    ]
  }
}

running browserify -r ./Scripts/lib/ReportViewer-8.0.14.225.js -o libs.js is resulting in the kendo-web dep to output in lib.js as

kendo = global.kendo = require("C:\\Projects\\Scripts\\lib\\kendo.web.js");

the issue being i'm not super excited about exposing fs structure here when it isn't necessary? I am not sure why it isn't just using require('kendo-web') any thoughts on what is happening, has it always worked like this and i didn't notice? i'm using the latest version of browserify-shim

Cannot run jquery example

I'm totally new to browserify so I don't know what I might be doing wrong. So I tried to run the jquery example, but none of the methods work.

Going the "type a lot" method gives a through module not found error:

pataleta:examples sole$ cd shim-jquery/
pataleta:shim-jquery sole$ ls
Readme.md    build.js     index.html   js           package.json
pataleta:shim-jquery sole$ less package.json
pataleta:shim-jquery sole$ npm install
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/browserify
npm http 200 https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/request/-/request-2.12.0.tgz
npm http 200 https://registry.npmjs.org/browserify
npm http GET https://registry.npmjs.org/browserify/-/browserify-2.4.3.tgz
npm http 200 https://registry.npmjs.org/request/-/request-2.12.0.tgz
npm http 200 https://registry.npmjs.org/browserify/-/browserify-2.4.3.tgz
npm http GET https://registry.npmjs.org/shell-quote
npm http GET https://registry.npmjs.org/duplexer
npm http GET https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/insert-module-globals
npm http GET https://registry.npmjs.org/syntax-error
npm http GET https://registry.npmjs.org/browser-resolve
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/JSONStream
npm http GET https://registry.npmjs.org/module-deps
npm http GET https://registry.npmjs.org/browser-pack
npm http 200 https://registry.npmjs.org/duplexer
npm http GET https://registry.npmjs.org/duplexer/-/duplexer-0.0.4.tgz
npm http 200 https://registry.npmjs.org/syntax-error
npm http GET https://registry.npmjs.org/syntax-error/-/syntax-error-0.0.1.tgz
npm http 200 https://registry.npmjs.org/shell-quote
npm http GET https://registry.npmjs.org/shell-quote/-/shell-quote-0.0.1.tgz
npm http 200 https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/through/-/through-2.2.7.tgz
npm http 200 https://registry.npmjs.org/insert-module-globals
npm http 200 https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-0.1.3.tgz
npm http GET https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz
npm http 200 https://registry.npmjs.org/browser-resolve
npm http GET https://registry.npmjs.org/browser-resolve/-/browser-resolve-0.0.5.tgz
npm http 200 https://registry.npmjs.org/JSONStream
npm http GET https://registry.npmjs.org/JSONStream/-/JSONStream-0.4.4.tgz
npm http 200 https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz
npm http 200 https://registry.npmjs.org/duplexer/-/duplexer-0.0.4.tgz
npm http 200 https://registry.npmjs.org/syntax-error/-/syntax-error-0.0.1.tgz
npm http 200 https://registry.npmjs.org/browser-pack
npm http GET https://registry.npmjs.org/browser-pack/-/browser-pack-0.3.0.tgz
npm http 200 https://registry.npmjs.org/module-deps
npm http 200 https://registry.npmjs.org/shell-quote/-/shell-quote-0.0.1.tgz
npm http GET https://registry.npmjs.org/module-deps/-/module-deps-0.5.3.tgz
npm http 200 https://registry.npmjs.org/through/-/through-2.2.7.tgz
npm http 200 https://registry.npmjs.org/browser-resolve/-/browser-resolve-0.0.5.tgz
npm http 200 https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz
npm http 200 https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-0.1.3.tgz
npm http 200 https://registry.npmjs.org/JSONStream/-/JSONStream-0.4.4.tgz
npm http 200 https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz
npm http 200 https://registry.npmjs.org/browser-pack/-/browser-pack-0.3.0.tgz
npm http 200 https://registry.npmjs.org/module-deps/-/module-deps-0.5.3.tgz
npm http GET https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/uglify-js/1.3.4
npm http GET https://registry.npmjs.org/commondir
npm http GET https://registry.npmjs.org/lexical-scope
npm http GET https://registry.npmjs.org/process
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/detective
npm http GET https://registry.npmjs.org/concat-stream
npm http GET https://registry.npmjs.org/resolve/0.3.0
npm http GET https://registry.npmjs.org/console-browserify/0.1.6
npm http GET https://registry.npmjs.org/vm-browserify/0.0.1
npm http GET https://registry.npmjs.org/crypto-browserify/0.2.1
npm http GET https://registry.npmjs.org/http-browserify/0.1.6
npm http GET https://registry.npmjs.org/buffer-browserify/0.0.4
npm http GET https://registry.npmjs.org/zlib-browserify/0.0.1
npm http GET https://registry.npmjs.org/jsonparse/0.0.5
npm http 200 https://registry.npmjs.org/commondir
npm http 200 https://registry.npmjs.org/process
npm http GET https://registry.npmjs.org/commondir/-/commondir-0.0.1.tgz
npm http GET https://registry.npmjs.org/process/-/process-0.5.1.tgz
npm http 200 https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/esprima/-/esprima-0.9.9.tgz
npm http 200 https://registry.npmjs.org/uglify-js/1.3.4
npm http GET https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.4.tgz
npm http 200 https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz
npm http 200 https://registry.npmjs.org/lexical-scope
npm http GET https://registry.npmjs.org/lexical-scope/-/lexical-scope-0.0.14.tgz
npm http 200 https://registry.npmjs.org/detective
npm http 200 https://registry.npmjs.org/concat-stream
npm http GET https://registry.npmjs.org/detective/-/detective-2.0.0.tgz
npm http GET https://registry.npmjs.org/concat-stream/-/concat-stream-0.1.1.tgz
npm http 200 https://registry.npmjs.org/resolve
npm http 200 https://registry.npmjs.org/resolve/0.3.0
npm http GET https://registry.npmjs.org/resolve/-/resolve-0.3.1.tgz
npm http GET https://registry.npmjs.org/resolve/-/resolve-0.3.0.tgz
npm http 200 https://registry.npmjs.org/vm-browserify/0.0.1
npm http GET https://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.1.tgz
npm http 200 https://registry.npmjs.org/console-browserify/0.1.6
npm http GET https://registry.npmjs.org/console-browserify/-/console-browserify-0.1.6.tgz
npm http 200 https://registry.npmjs.org/crypto-browserify/0.2.1
npm http GET https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-0.2.1.tgz
npm http 200 https://registry.npmjs.org/buffer-browserify/0.0.4
npm http GET https://registry.npmjs.org/buffer-browserify/-/buffer-browserify-0.0.4.tgz
npm http 200 https://registry.npmjs.org/zlib-browserify/0.0.1
npm http GET https://registry.npmjs.org/zlib-browserify/-/zlib-browserify-0.0.1.tgz
npm http 200 https://registry.npmjs.org/commondir/-/commondir-0.0.1.tgz
npm http 200 https://registry.npmjs.org/process/-/process-0.5.1.tgz
npm http 200 https://registry.npmjs.org/http-browserify/0.1.6
npm http GET https://registry.npmjs.org/http-browserify/-/http-browserify-0.1.6.tgz
npm http 200 https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.4.tgz
npm http 200 https://registry.npmjs.org/jsonparse/0.0.5
npm http 200 https://registry.npmjs.org/esprima/-/esprima-0.9.9.tgz
npm http GET https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz
npm http 200 https://registry.npmjs.org/lexical-scope/-/lexical-scope-0.0.14.tgz
npm http 200 https://registry.npmjs.org/detective/-/detective-2.0.0.tgz
npm http 200 https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz
npm http 200 https://registry.npmjs.org/concat-stream/-/concat-stream-0.1.1.tgz
npm http 200 https://registry.npmjs.org/resolve/-/resolve-0.3.1.tgz
npm http 200 https://registry.npmjs.org/resolve/-/resolve-0.3.0.tgz
npm http 200 https://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.1.tgz
npm http 200 https://registry.npmjs.org/console-browserify/-/console-browserify-0.1.6.tgz
npm http 200 https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-0.2.1.tgz
npm http 200 https://registry.npmjs.org/buffer-browserify/-/buffer-browserify-0.0.4.tgz
npm http 200 https://registry.npmjs.org/zlib-browserify/-/zlib-browserify-0.0.1.tgz
npm http 200 https://registry.npmjs.org/http-browserify/-/http-browserify-0.1.6.tgz
npm http 200 https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz
npm http GET https://registry.npmjs.org/esprima/1.0.2
npm http GET https://registry.npmjs.org/escodegen/0.0.15
npm http GET https://registry.npmjs.org/base64-js/0.0.2
npm http GET https://registry.npmjs.org/concat-stream/0.0.8
npm http GET https://registry.npmjs.org/astw
npm http 200 https://registry.npmjs.org/esprima/1.0.2
npm http GET https://registry.npmjs.org/esprima/-/esprima-1.0.2.tgz
npm http 200 https://registry.npmjs.org/escodegen/0.0.15
npm http GET https://registry.npmjs.org/escodegen/-/escodegen-0.0.15.tgz
npm http 200 https://registry.npmjs.org/base64-js/0.0.2
npm http GET https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz
npm http 200 https://registry.npmjs.org/concat-stream/0.0.8
npm http GET https://registry.npmjs.org/concat-stream/-/concat-stream-0.0.8.tgz
npm http 200 https://registry.npmjs.org/astw
npm http GET https://registry.npmjs.org/astw/-/astw-0.0.0.tgz
npm http 200 https://registry.npmjs.org/esprima/-/esprima-1.0.2.tgz
npm http 200 https://registry.npmjs.org/escodegen/-/escodegen-0.0.15.tgz
npm http 200 https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz
npm http 200 https://registry.npmjs.org/concat-stream/-/concat-stream-0.0.8.tgz
npm http 200 https://registry.npmjs.org/astw/-/astw-0.0.0.tgz
npm http GET https://registry.npmjs.org/source-map
npm http 200 https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/source-map/-/source-map-0.1.27.tgz
npm http 200 https://registry.npmjs.org/source-map/-/source-map-0.1.27.tgz
npm http GET https://registry.npmjs.org/amdefine
npm http 200 https://registry.npmjs.org/amdefine
npm http GET https://registry.npmjs.org/amdefine/-/amdefine-0.0.5.tgz
npm http 200 https://registry.npmjs.org/amdefine/-/amdefine-0.0.5.tgz
[email protected] node_modules/request

[email protected] node_modules/browserify
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ””โ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
pataleta:shim-jquery sole$ ls
Readme.md    build.js     index.html   js           node_modules package.json
pataleta:shim-jquery sole$ node build.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'through'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/sole/tmp/browserify-shim/index.js:6:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
pataleta:shim-jquery sole$ npm install through
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/through
npm http 304 https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/through/-/through-2.3.4.tgz
npm http 200 https://registry.npmjs.org/through/-/through-2.3.4.tgz
[email protected] node_modules/through
pataleta:shim-jquery sole$ node build.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'through'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/sole/tmp/browserify-shim/index.js:6:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

So I tried the "short route", cloning again but with npm install, and running the steps you mentioned, which also failed:

pataleta:browserify-shimkk sole$ npm install browserify-shim
npm http GET https://registry.npmjs.org/browserify-shim
npm http 200 https://registry.npmjs.org/browserify-shim
npm http GET https://registry.npmjs.org/browserify-shim/-/browserify-shim-2.0.7.tgz
npm http 200 https://registry.npmjs.org/browserify-shim/-/browserify-shim-2.0.7.tgz
npm http GET https://registry.npmjs.org/through
npm http 304 https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/browserify
npm http 304 https://registry.npmjs.org/browserify
npm http GET https://registry.npmjs.org/browserify/-/browserify-2.25.1.tgz
npm http 200 https://registry.npmjs.org/browserify/-/browserify-2.25.1.tgz
npm http GET https://registry.npmjs.org/deps-sort
npm http GET https://registry.npmjs.org/event-stream
npm http GET https://registry.npmjs.org/module-deps
npm http GET https://registry.npmjs.org/browser-pack
npm http GET https://registry.npmjs.org/browser-builtins
npm http GET https://registry.npmjs.org/umd
npm http GET https://registry.npmjs.org/parents
npm http GET https://registry.npmjs.org/shell-quote
npm http GET https://registry.npmjs.org/duplexer
npm http GET https://registry.npmjs.org/concat-stream
npm http GET https://registry.npmjs.org/insert-module-globals
npm http GET https://registry.npmjs.org/syntax-error
npm http GET https://registry.npmjs.org/browser-resolve
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/JSONStream
npm http 304 https://registry.npmjs.org/module-deps
npm http GET https://registry.npmjs.org/module-deps/-/module-deps-1.0.1.tgz
npm http 304 https://registry.npmjs.org/browser-pack
npm http GET https://registry.npmjs.org/browser-pack/-/browser-pack-0.9.4.tgz
npm http 200 https://registry.npmjs.org/browser-builtins
npm http 200 https://registry.npmjs.org/deps-sort
npm http GET https://registry.npmjs.org/deps-sort/-/deps-sort-0.1.1.tgz
npm http GET https://registry.npmjs.org/browser-builtins/-/browser-builtins-1.0.4.tgz
npm http 200 https://registry.npmjs.org/umd
npm http GET https://registry.npmjs.org/umd/-/umd-1.1.1.tgz
npm http 304 https://registry.npmjs.org/shell-quote
npm http 200 https://registry.npmjs.org/parents
npm http 304 https://registry.npmjs.org/duplexer
npm http GET https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz
npm http GET https://registry.npmjs.org/parents/-/parents-0.0.1.tgz
npm http 304 https://registry.npmjs.org/concat-stream
npm http 304 https://registry.npmjs.org/insert-module-globals
npm http 304 https://registry.npmjs.org/browser-resolve
npm http 304 https://registry.npmjs.org/syntax-error
npm http GET https://registry.npmjs.org/concat-stream/-/concat-stream-1.0.0.tgz
npm http GET https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-1.2.0.tgz
npm http GET https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.1.1.tgz
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/JSONStream
npm http GET https://registry.npmjs.org/optimist/-/optimist-0.5.2.tgz
npm http GET https://registry.npmjs.org/JSONStream/-/JSONStream-0.6.4.tgz
npm http 200 https://registry.npmjs.org/module-deps/-/module-deps-1.0.1.tgz
npm http 200 https://registry.npmjs.org/browser-pack/-/browser-pack-0.9.4.tgz
npm http 200 https://registry.npmjs.org/deps-sort/-/deps-sort-0.1.1.tgz
npm http 200 https://registry.npmjs.org/browser-builtins/-/browser-builtins-1.0.4.tgz
npm http 200 https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz
npm http 200 https://registry.npmjs.org/umd/-/umd-1.1.1.tgz
npm http 200 https://registry.npmjs.org/parents/-/parents-0.0.1.tgz
npm http 200 https://registry.npmjs.org/concat-stream/-/concat-stream-1.0.0.tgz
npm http 200 https://registry.npmjs.org/event-stream
npm http 200 https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-1.2.0.tgz
npm http GET https://registry.npmjs.org/event-stream/-/event-stream-3.0.16.tgz
npm http 200 https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.1.1.tgz
npm http 200 https://registry.npmjs.org/optimist/-/optimist-0.5.2.tgz
npm http 200 https://registry.npmjs.org/JSONStream/-/JSONStream-0.6.4.tgz
npm http 200 https://registry.npmjs.org/event-stream/-/event-stream-3.0.16.tgz
npm http GET https://registry.npmjs.org/uglify-js
npm http GET https://registry.npmjs.org/rfile
npm http GET https://registry.npmjs.org/ruglify
npm http GET https://registry.npmjs.org/minimist
npm http GET https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/combine-source-map
npm http GET https://registry.npmjs.org/from
npm http GET https://registry.npmjs.org/map-stream/0.0.2
npm http GET https://registry.npmjs.org/pause-stream/0.0.10
npm http GET https://registry.npmjs.org/split
npm http GET https://registry.npmjs.org/stream-combiner/0.0.0
npm http GET https://registry.npmjs.org/resolve/0.4.0
npm http GET https://registry.npmjs.org/punycode
npm http GET https://registry.npmjs.org/vm-browserify
npm http GET https://registry.npmjs.org/console-browserify
npm http GET https://registry.npmjs.org/crypto-browserify
npm http GET https://registry.npmjs.org/http-browserify
npm http GET https://registry.npmjs.org/buffer-browserify
npm http GET https://registry.npmjs.org/zlib-browserify
npm http GET https://registry.npmjs.org/constants-browserify
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/commondir
npm http GET https://registry.npmjs.org/lexical-scope
npm http GET https://registry.npmjs.org/process
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/detective
npm http GET https://registry.npmjs.org/jsonparse/0.0.5
npm http 304 https://registry.npmjs.org/esprima
npm http 200 https://registry.npmjs.org/rfile
npm http GET https://registry.npmjs.org/rfile/-/rfile-1.0.0.tgz
npm http 200 https://registry.npmjs.org/ruglify
npm http GET https://registry.npmjs.org/ruglify/-/ruglify-1.0.0.tgz
npm http 200 https://registry.npmjs.org/minimist
npm http GET https://registry.npmjs.org/minimist/-/minimist-0.0.1.tgz
npm http 200 https://registry.npmjs.org/combine-source-map
npm http 200 https://registry.npmjs.org/from
npm http GET https://registry.npmjs.org/combine-source-map/-/combine-source-map-0.1.3.tgz
npm http GET https://registry.npmjs.org/from/-/from-0.1.3.tgz
npm http 200 https://registry.npmjs.org/map-stream/0.0.2
npm http GET https://registry.npmjs.org/map-stream/-/map-stream-0.0.2.tgz
npm http 200 https://registry.npmjs.org/pause-stream/0.0.10
npm http GET https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.10.tgz
npm http 200 https://registry.npmjs.org/stream-combiner/0.0.0
npm http GET https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.0.tgz
npm http 200 https://registry.npmjs.org/split
npm http GET https://registry.npmjs.org/split/-/split-0.2.6.tgz
npm http 200 https://registry.npmjs.org/resolve/0.4.0
npm http GET https://registry.npmjs.org/resolve/-/resolve-0.4.0.tgz
npm http 200 https://registry.npmjs.org/rfile/-/rfile-1.0.0.tgz
npm http 200 https://registry.npmjs.org/ruglify/-/ruglify-1.0.0.tgz
npm http 200 https://registry.npmjs.org/vm-browserify
npm http 200 https://registry.npmjs.org/console-browserify
npm http 200 https://registry.npmjs.org/crypto-browserify
npm http 200 https://registry.npmjs.org/minimist/-/minimist-0.0.1.tgz
npm http GET https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-0.2.3.tgz
npm http 200 https://registry.npmjs.org/punycode
npm http GET https://registry.npmjs.org/punycode/-/punycode-1.2.3.tgz
npm http 200 https://registry.npmjs.org/map-stream/-/map-stream-0.0.2.tgz
npm http 200 https://registry.npmjs.org/combine-source-map/-/combine-source-map-0.1.3.tgz
npm http 200 https://registry.npmjs.org/from/-/from-0.1.3.tgz
npm http 200 https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.10.tgz
npm http 200 https://registry.npmjs.org/zlib-browserify
npm http 200 https://registry.npmjs.org/buffer-browserify
npm http GET https://registry.npmjs.org/buffer-browserify/-/buffer-browserify-0.1.0.tgz
npm http 200 https://registry.npmjs.org/constants-browserify
npm http GET https://registry.npmjs.org/constants-browserify/-/constants-browserify-0.0.1.tgz
npm http 200 https://registry.npmjs.org/http-browserify
npm http GET https://registry.npmjs.org/http-browserify/-/http-browserify-0.1.11.tgz
npm http 200 https://registry.npmjs.org/uglify-js
npm http 304 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/wordwrap
npm http 200 https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.0.tgz
npm http 304 https://registry.npmjs.org/commondir
npm http 200 https://registry.npmjs.org/resolve/-/resolve-0.4.0.tgz
npm http 200 https://registry.npmjs.org/split/-/split-0.2.6.tgz
npm http 200 https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-0.2.3.tgz
npm http GET https://registry.npmjs.org/uglify-js/-/uglify-js-2.2.5.tgz
npm http 304 https://registry.npmjs.org/lexical-scope
npm http 200 https://registry.npmjs.org/punycode/-/punycode-1.2.3.tgz
npm http 304 https://registry.npmjs.org/process
npm http 304 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/jsonparse/0.0.5
npm http 304 https://registry.npmjs.org/detective
npm http GET https://registry.npmjs.org/detective/-/detective-2.1.2.tgz
npm http 200 https://registry.npmjs.org/buffer-browserify/-/buffer-browserify-0.1.0.tgz
npm http 200 https://registry.npmjs.org/constants-browserify/-/constants-browserify-0.0.1.tgz
npm http 200 https://registry.npmjs.org/http-browserify/-/http-browserify-0.1.11.tgz
npm http 200 https://registry.npmjs.org/uglify-js/-/uglify-js-2.2.5.tgz
npm http 200 https://registry.npmjs.org/detective/-/detective-2.1.2.tgz
npm http GET https://registry.npmjs.org/convert-source-map
npm http GET https://registry.npmjs.org/parse-base64vlq-mappings
npm http GET https://registry.npmjs.org/inline-source-map
npm http GET https://registry.npmjs.org/duplexer/0.0.2
npm http 200 https://registry.npmjs.org/parse-base64vlq-mappings
npm http GET https://registry.npmjs.org/parse-base64vlq-mappings/-/parse-base64vlq-mappings-0.1.4.tgz
npm http GET https://registry.npmjs.org/astw
npm http 200 https://registry.npmjs.org/convert-source-map
npm http GET https://registry.npmjs.org/convert-source-map/-/convert-source-map-0.2.6.tgz
npm http 200 https://registry.npmjs.org/inline-source-map
npm http GET https://registry.npmjs.org/inline-source-map/-/inline-source-map-0.2.5.tgz
npm http GET https://registry.npmjs.org/esprima/1.0.2
npm http GET https://registry.npmjs.org/escodegen/0.0.15
npm http 200 https://registry.npmjs.org/duplexer/0.0.2
npm http GET https://registry.npmjs.org/duplexer/-/duplexer-0.0.2.tgz
npm http 200 https://registry.npmjs.org/parse-base64vlq-mappings/-/parse-base64vlq-mappings-0.1.4.tgz
npm http 304 https://registry.npmjs.org/astw
npm http 200 https://registry.npmjs.org/convert-source-map/-/convert-source-map-0.2.6.tgz
npm http 200 https://registry.npmjs.org/inline-source-map/-/inline-source-map-0.2.5.tgz
npm http 304 https://registry.npmjs.org/escodegen/0.0.15
npm http 304 https://registry.npmjs.org/esprima/1.0.2
npm http GET https://registry.npmjs.org/callsite
npm http 200 https://registry.npmjs.org/duplexer/-/duplexer-0.0.2.tgz
npm http GET https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/source-map
npm http 200 https://registry.npmjs.org/callsite
npm http GET https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz
npm http 304 https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/base64-js/0.0.2
npm http 304 https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/amdefine
npm http 304 https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/concat-stream/0.0.8
npm http 200 https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz
npm http 304 https://registry.npmjs.org/base64-js/0.0.2
npm http 304 https://registry.npmjs.org/amdefine
npm http 304 https://registry.npmjs.org/concat-stream/0.0.8
[email protected] node_modules/browserify
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ””โ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules/browserify-shim
โ””โ”€โ”€ [email protected]
pataleta:browserify-shimkk sole$ npm explore browserify-shim

Exploring /Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim
Type 'exit' or ^D when finished

bash-3.2$ npm run shim-jquery

> [email protected] shim-jquery /Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim
> npm install opener && cd examples/shim-jquery && npm install && node build.js && opener index.html

npm http GET https://registry.npmjs.org/opener
npm http 200 https://registry.npmjs.org/opener
npm http GET https://registry.npmjs.org/opener/-/opener-1.3.0.tgz
npm http 200 https://registry.npmjs.org/opener/-/opener-1.3.0.tgz
[email protected] node_modules/opener
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/browserify
npm http 304 https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/browserify
npm http GET https://registry.npmjs.org/shell-quote
npm http GET https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/duplexer
npm http GET https://registry.npmjs.org/insert-module-globals
npm http GET https://registry.npmjs.org/syntax-error
npm http GET https://registry.npmjs.org/browser-resolve
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/JSONStream
npm http GET https://registry.npmjs.org/browser-pack
npm http GET https://registry.npmjs.org/module-deps
npm http 304 https://registry.npmjs.org/through
npm http 304 https://registry.npmjs.org/shell-quote
npm http 304 https://registry.npmjs.org/duplexer
npm http 304 https://registry.npmjs.org/insert-module-globals
npm http 304 https://registry.npmjs.org/syntax-error
npm http 304 https://registry.npmjs.org/browser-resolve
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/JSONStream
npm http 304 https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/browser-pack
npm http 304 https://registry.npmjs.org/module-deps
npm http GET https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/uglify-js/1.3.4
npm http GET https://registry.npmjs.org/process
npm http GET https://registry.npmjs.org/commondir
npm http GET https://registry.npmjs.org/lexical-scope
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/concat-stream
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/detective
npm http GET https://registry.npmjs.org/vm-browserify/0.0.1
npm http GET https://registry.npmjs.org/resolve/0.3.0
npm http GET https://registry.npmjs.org/console-browserify/0.1.6
npm http GET https://registry.npmjs.org/crypto-browserify/0.2.1
npm http GET https://registry.npmjs.org/http-browserify/0.1.6
npm http GET https://registry.npmjs.org/buffer-browserify/0.0.4
npm http GET https://registry.npmjs.org/zlib-browserify/0.0.1
npm http GET https://registry.npmjs.org/jsonparse/0.0.5
npm http 304 https://registry.npmjs.org/esprima
npm http 304 https://registry.npmjs.org/uglify-js/1.3.4
npm http 304 https://registry.npmjs.org/process
npm http 304 https://registry.npmjs.org/lexical-scope
npm http 304 https://registry.npmjs.org/commondir
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/concat-stream
npm http 304 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/detective
npm http 304 https://registry.npmjs.org/resolve/0.3.0
npm http 304 https://registry.npmjs.org/vm-browserify/0.0.1
npm http 304 https://registry.npmjs.org/console-browserify/0.1.6
npm http 304 https://registry.npmjs.org/crypto-browserify/0.2.1
npm http 304 https://registry.npmjs.org/http-browserify/0.1.6
npm http 304 https://registry.npmjs.org/buffer-browserify/0.0.4
npm http 304 https://registry.npmjs.org/zlib-browserify/0.0.1
npm http GET https://registry.npmjs.org/esprima/1.0.2
npm http GET https://registry.npmjs.org/escodegen/0.0.15
npm http 304 https://registry.npmjs.org/jsonparse/0.0.5
npm http GET https://registry.npmjs.org/base64-js/0.0.2
npm http GET https://registry.npmjs.org/concat-stream/0.0.8
npm http GET https://registry.npmjs.org/astw
npm http 304 https://registry.npmjs.org/escodegen/0.0.15
npm http 304 https://registry.npmjs.org/esprima/1.0.2
npm http GET https://registry.npmjs.org/source-map
npm http 304 https://registry.npmjs.org/base64-js/0.0.2
npm http 304 https://registry.npmjs.org/concat-stream/0.0.8
npm http 304 https://registry.npmjs.org/astw
npm http 304 https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/amdefine
npm http 304 https://registry.npmjs.org/amdefine
[email protected] node_modules/request

[email protected] node_modules/browserify
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ””โ”€โ”€ [email protected] ([email protected], [email protected], [email protected])

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/js/build/bundle.js'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.writeFileSync (fs.js:966:15)
    at /Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/build.js:21:8
    at Stream.<anonymous> (/Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/node_modules/browserify/index.js:141:35)
    at Stream.EventEmitter.emit (events.js:117:20)
    at Stream.handleEnd (/Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/node_modules/browserify/node_modules/duplexer/index.js:71:21)
    at Stream.EventEmitter.emit (events.js:117:20)
    at drain (/Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/node_modules/browserify/node_modules/through/index.js:33:23)
    at Stream.stream.queue.stream.push (/Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/node_modules/browserify/node_modules/through/index.js:41:5)
    at Stream.end (/Users/sole/tmp/browserify-shimkk/node_modules/browserify-shim/examples/shim-jquery/node_modules/browserify/index.js:263:14)
npm ERR! weird error 8
npm ERR! not ok code 0

Not sure if there's anything else I can do to find out what is going on?

Support Browserify 4.x

Hi, I'm currently blocked from using browserify-shim with my project since I'm using browserify 4.1.x. Are there any major changes required to support v4+?

Required node_module can't use globally shimmed jquery

I've created a minimal repo that will hopefully demonstrate this issue better than I can explain it: https://github.com/mlms13/shim-bug/tree/master

If your working on a project that shims, for example, jquery, and that project requires a module from node_modules (let's call it foo), if foo has a require('jquery'), browserify won't build successfully. This is only the case if foo has its own package.json. If you delete foo's package.json, foo gains access to the shimmed jquery and the project builds.

I'm running into this during the process of migrating from Grunt to Gulp. The Gruntfile depended on an older version of browserify and browserify-shim. Now that I'm abandoning Grunt, I upgraded browserify to 4.1.6 and browserify-shim to 3.5.0, an I run into this issue when I run browserify index.js -o bundle.js.

Hopefully the test repo explains it better than I did here. Let me know if anything doesn't make sense, or if I'm doing something wrong.

'Cannot find module' for Globals

I've been trying to create a project that utilizes AngularJS, Browserify and Gulp for an excellent developer experience, one that produces a distributable 'module' (in Angular parlance).

We've had great results with Gulp, but we're having trouble with browserify-shim. Also, unfortunately, most of the examples out there either don't use gulp, or use gulp-browserify, which has been blacklisted/ended.

We're including AngularJS and JQuery from Google CDN as <script> tags and have declared "angular" : "global:angular" and "jquery" : "global:$" in our browserify-shim config in package.json, but we're getting "cannot find module" when we try to user var angular = require('angular') and var $ = require('jquery') inside of our browserified-code (once it runs in the browser).

I've created a sample project that distills this down close to the minimum.
It's available at https://github.com/ryan-kimber/multi-browserify
Once cloned, you would run 'npm install', then 'bower install', then 'gulp' to generate the files and run the test server. You can access the live HTML at http://localhost:4000/gulp.html

Any help would be appreciated, but I'm also wondering if we've come across a bug/issue with the intersection of gulp, browserify, vinyl-source-stream, etc.

Not worked when debug = false

When debug set false show error: if (position < 0) throw new Error('unable to shim the given bundle because s
Need search
require.define("__browserify_process",function(
instead
require.define("__browserify_process",Function([
in lib/get-injectposition.js:17 must be
/^[ ]*require.define("__browserify_process", *[F,f]unction(/m

Unable to external a jquery

I want all the vendor libraries to be in a separate js file and then uglified, so I tried the following:

var browserify = require('browserify')
, shim = require('browserify-shim'),
fs = require("fs");

require('streamline').register();

shim(browserify(), {
// jQuery attaches itself to the window as '$' so we assign the exports accordingly
jquery: { path: './js/vendor/jquery-1.9.1.min.js', exports: '$' }
})
.require(require.resolve('./js/entry.js'), { entry: true })
.external("underscore")
.external("jquery")
.bundle(function (err, src) {
if (err) return console.error(err);

fs.writeFileSync("app.js", src);
});

Underscore works perfectly, but the ".external("jquery")" causes:
Error: module "jquery" not found in require()

Am I doing something wrong?
Thanks, Clayton

Cannot shim wysihtml5

I'm upgrading to browserify v2, and have been using your shim for awhile. With v1, I was able to shim wysithml5 (https://github.com/xing/wysihtml5) without any problems. With the latest version, I can't seem to shim wysihtml5. I created a simple example that demonstrates the problem:

https://github.com/SpiderStrategies/browserify-wysihtml

node index.js

You'll see an error:

Parsing file /Volumes/Bertha/users/koopa/development/playground/browserify-wysihtml/wysihtml5-0.4.0pre.js: Cannot set property 'parent' of null

I'm betting it's something funky in wysihtml5. Do you have any ideas of how we can get around this problem?

Shim produces different wrappers on Windows vs. Mac

This one's a bit of a doozy. Will be giving into the code again this week to see if I can resolve this one as well.

I'm building a libs.js bundle that contains a handful of js libs, all of them non-CommonJS-compatible. The following shim is used in the package.json:

"browserify-shim": {
    "angular": {
        "exports": "angular"
    },
    "angular-route": {
        "depends": [
            "angular"
        ]
    },
    "angular-sanitize": {
        "depends": [
            "angular"
        ]
    },
    "angular-touch": {
        "depends": [
            "angular"
        ]
    },
    "jquery": {
        "exports": "jQuery"
    },
    "jquery-ui-core": {
        "depends": [
            "jquery"
        ]
    },
    "jquery-ui-datepicker": {
        "depends": [
            "jquery-ui-core"
        ]
    },
    "underscore": {
        "exports": "_"
    }
}

I've got exactly the same versions of browserify and browserify-shim installed on both machines: 3.41.0 for browserify (global), 3.41.0 for browserify (local), 3.4.1 for the shim (local). Versions do seem irrelevant, though; tried a bunch of combinations.

Upon running my browserify command, the first ten lines of my compiled libs.js look like this:

Windows:

require=(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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})({"RMfWRV":[function(require,module,exports){
(function (global){

; require("C:\\Users\\jmars32\\Projects\\gift-registry\\bower_components\\angular\\angular.js");
;__browserify_shim_require__=require;(function browserifyShim(module, define, require) {

Mac:

require=(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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})({"angular-route":[function(require,module,exports){
module.exports=require('KeHKU6');
},{}],"KeHKU6":[function(require,module,exports){
(function (global){

; require("/Users/gtalar0/Desktop/projects/gift-registry-git/bower_components/angular/angular.js");
;__browserify_shim_require__=require;(function browserifyShim(module, define, require) {

The difference here is obvious: the Mac version produces different wrappers and aliases than the Windows version.

I'll try to whip up a repo that demonstrates this with a few libs, but obviously the browserify process needs to be run both on a Windows and Mac machine to see differing output. It's very strange: the end result is that exports aren't working properly on the Mac version; wrapping libs like underscore (which produces both CommonJS and global values) results in the Mac version producing a bundle that DOESN'T expose _, even if it's explicitly exported, such as in my package.json.

I'm wondering if this could be the reason for the problem @jfsiii was having on this issue, regarding his trouble getting exports to work the same way mine do. I'm on a Windows machine, and I'd bet anything he's on a Mac.

Will start digging through the code and see what I can find.

Shim dependents without window

Currently you can specify dependents for a file, however the documentation says that these will be loaded onto the window object. Is it also possible to provide dependents without putting them on the window object? Basically wrapping files, from (as an example):

(function ($) {
  โ€ฆ
})($)

to:

var $ = require('jquery')

(function ($) {
  โ€ฆ
})($)

Support passing options directly to transform function

Currently, the only config that can be passed to browserify-shim is via package.json (although package.json can point to an external config file). There are certain times when passing options directly to the transform function can be useful, for example, when browserify-shim is run multiple times in the same project but with different settings.

strange module names on bundle(), non working code

Hi! I'm trying to create browserify version of angular .
I'm doing this:

  shim(browserify(), {
    "angular": { path: './build/angular.js', exports: 'angular' },
    "angular-cookies": { path: './build/angular-cookies.js', exports: 'angular-cookies', depends: {"angular":"angular"} },
    "angular-resource": { path: './build/angular-resource.js', exports: 'angular-resource', depends: {"angular":"angular"} },
  })
  .bundle({},function (err, src) {
    if (err) return console.error(err);
    fs.writeFileSync(OUTPUT, src);
  });

The output file is looking strange, there is garbage looking module exports , called reBOaC, BgUQU8 and etc.

If i'm trying to browserify another script, which requests the output file I get:

>> Error: module "reBOaC" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "angular" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "0uVZ57" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "angular" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "BgUQU8" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "angular" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "Ub6SoA" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "angular" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "97JKBw" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "angular" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "WckBoe" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js
>> Error: module "zAWsm7" not found from "/Volumes/work/Projects/yaas/node_modules/AngularJS/browserifiedAngular.js"
File written to: ./build/development/js/app.js

Output file

Unable to shim global modules from external shim.js file

According to the docs, it's currently possible to use the global:* syntax to shim a global module (translated into window.*) from the package.json file.
However, this functionality is seemingly missing if the shim configuration is moved to a separate .js file.

Why does `"exports": "x"` always attach `x` to the global namespace?

I need to shim a jQuery-plugin to make it work with browserify. Therefore I added this to my package.json:

{
  "browser": {
    "jquery": "./bower_components/jquery/dist/jquery.js",
    "jquery-ui-core": "./bower_components/jquery-ui/ui/jquery.ui.core.js"
  },
  "browserify-shim": {
    "jquery": "$",
    "jquery-ui-core": {
      "depends": ["jquery"],
      "exports": null
    }
  }
}

My JavaScript:

var $ = require('jquery');
require('jquery-ui-core');

console.log($.ui); // outputs the jquery-ui object
console.log(window.$.ui); // also outputs the jquery-ui object

I donโ€™t like to have $ in the global namespace.

If I shim jquery-ui-core manually, it works without the need to add $ to window.

Hereโ€™s the diff:

--- ./bower_components/jquery-ui/ui/jquery.ui.core.js
+++ ./bower_components/jquery-ui/ui/jquery.ui.core-shimmed.js
@@ -8,6 +8,9 @@
  *
  * http://api.jqueryui.com/category/ui-core/
  */
+
+var jQuery = require('jquery');
+
 (function( $, undefined ) {

 var uuid = 0,

The JavaScript for it:

var $ = require('jquery');
require('../bower_components/jquery-ui/ui/jquery.ui.core-shimmed.js');

console.log($.ui); // outputs the jquery-ui object
console.log(window.$.ui); // obviously throws a TypeError, because $ is not attached to window

Is there a way to prevent that browserify-shim adds the exports to the window object, or is this a forced behaviour?

Unable to find a browserify-shim config section in the package.json

I'm getting this when trying to require a file outside my app's directory. So just the presence of require('../hmm') will spit out

Error: Unable to find a browserify-shim config section in the package.json for /Users/bclinkinbeard/Code/scratch/bug-reports/b-shim/hmm.js
    at /Users/bclinkinbeard/Code/scratch/bug-reports/b-shim/app/node_modules/browserify-shim/lib/resolve-shims.js:163:38
    at /Users/bclinkinbeard/Code/scratch/bug-reports/b-shim/app/node_modules/browserify-shim/node_modules/mothership/index.js:27:31
    at testDir (/Users/bclinkinbeard/Code/scratch/bug-reports/b-shim/app/node_modules/browserify-shim/node_modules/mothership/node_modules/find-parent-dir/index.js:20:36)
    at /Users/bclinkinbeard/Code/scratch/bug-reports/b-shim/app/node_modules/browserify-shim/node_modules/mothership/node_modules/find-parent-dir/index.js:26:7
    at Object.cb [as oncomplete] (fs.js:168:19)

Building multiple bundles

browserify-shim is giving me some trouble trying to build multiple bundles. I don't see any documentation on building multiple bundles, so it might be a usecase that hasn't been fleshed out yet.

I'm trying to build 2 bundles: a libs bundle containing 3rd-party libraries that need to be shimmed, and an app bundle containing my application code. I want to be able to, for example, require('angular') from app, even though angular is defined in libs. "exports": "global:angular" should solve this, but I think it's running into trouble since browserify-shim is running twice. When it runs on libs, it needs angular to "exports": "angular", but when it runs on app, it needs to use global.

It seems like global is designed for use with script tags, but not external bundles. But there doesn't seem to be another way to reference external bundles.

Switching a dependency using the shim

I want to use Backbone with Lodash which are both being installed via npm. Inside of Backbone, there is a check for Underscore:

if (!_ && (typeof require !== 'undefined')) _ = require('underscore')

Using an alias, I have been able to have Backbone use Lodash instead, by adding the following to my package.json:

  "browser": {
    "backbone": "./node_modules/backbone/backbone.js"
  },
  "browserify-shim": {
    "backbone": {
      "exports": "Backbone",
      "depends": ["lodash:_"]
    }
  },
  "browserify": {
    "transform": ["browserify-shim"]
  },

Everything works fine as Backbone is now using Lodash. However, inspecting the bundled file, I still see that the Underscore library is being included in the output, which is not what I want at all.

It's possible that this could be an issue with Browserify itself but since I'm using Browserify Shim, I thought I would start here.

browserify-shim not finding module

Given the following:

main.js

var angular = require('angular');

package.json

{
  "main": "./main.js",
  "browser": {
    "angular": "./vendor/angular/angular.js"
  },
  "browserify-shim": {
    "angular": "angular"
  },
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "dependencies": {
    "browserify-shim": "~3.2.0"
  }
}

When running:

browserify . -d -o bundle.js

A bundle is successfully created and the output from the browserify-shim diagnostics is:

{
  file: 'D:\\development\\js\\browserify\\main.js',
  info:
  {
    package_json: 'D:\\development\\js\\browserify\\package.json',
    packageDir: 'D:\\development\\js\\browserify',
    shim: undefined,
    exposeGlobals:
    {},
    browser:
    {
      angular: './vendor/angular/angular.js'
    },
    'browserify-shim':
    {
      angular: 'angular'
    },
    dependencies:
    {
      'browserify-shim': '~3.2.0'
    },
    lookedUp: false
  },
  messages: ['Found "angular" in browser field referencing "./vendor/angular/angular.js" and resolved it to "D:\\development\\js\\browserify\\vendor\\angular\\angular.js"',
  {
    resolved:
    {
      'D:\\development\\js\\browserify\\vendor\\angular\\angular.js':
      {
        exports: 'angular',
        depends: undefined
      }
    }
  }]
}

{
  file: 'D:\\development\\js\\browserify\\vendor\\angular\\angular.js',
  info:
  {
    package_json: 'D:\\development\\js\\browserify\\package.json',
    packageDir: 'D:\\development\\js\\browserify\\',
    shim:
    {
      exports: 'angular',
      depends: undefined
    },
    exposeGlobals:
    {},
    browser:
    {
      angular: './vendor/angular/angular.js'
    },
    'browserify-shim':
    {
      angular: 'angular'
    },
    dependencies:
    {
      'browserify-shim': '~3.2.0'
    },
    lookedUp: false
  },
  messages: ['Found "angular" in browser field referencing "./vendor/angular/angular.js" and resolved it to "D:\\development\\js\\browserify\\vendor\\angular\\angular.js"',
  {
    resolved:
    {
      'D:\\development\\js\\browserify\\vendor\\angular\\angular.js':
      {
        exports: 'angular',
        depends: undefined
      }
    }
  }]
}

If package.json is changed to this (removing the browser section):

{
  "main": "./main.js",
  "browserify-shim": {
    "./vendor/angular/angular.js": "angular"
  },
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "dependencies": {
    "browserify-shim": "~3.2.0"
  }
}

I get the following error:

Error: module "angular" not found from "D:\development\js\browserify\main.js"

With the output from browserify-shim diagnostics as:

{
  file: 'D:\\development\\js\\browserify\\main.js',
  info:
  {
    package_json: 'D:\\development\\js\\browserify\\package.json',
    packageDir: 'D:\\development\\js\\browserify',
    shim: undefined,
    exposeGlobals:
    {},
    browser: undefined,
    'browserify-shim':
    {
      './vendor/angular/angular.js': 'angular'
    },
    dependencies:
    {
      'browserify-shim': '~3.2.0'
    },
    lookedUp: false
  },
  messages: ['Resolved "./vendor/angular/angular.js" found in package.json to "D:\\development\\js\\browserify\\vendor\\angular\\angular.js"',
  {
    resolved:
    {
      'D:\\development\\js\\browserify\\vendor\\angular\\angular.js':
      {
        exports: 'angular',
        depends: undefined
      }
    }
  }]
}
{
  [Error: module "angular"
    not found from "D:\\development\\js\\browserify\\main.js"
  ]
  filename: 'angular',
  parent: 'D:\\development\\js\\browserify\\main.js'
}

I was under the impression that the browser section was for configuring aliases and that the two different package.json files above should be equivalent.

Have I misunderstood?

gulp task not exporting globals

Ive been messing with this issue for some time and I just cant figure it out. Hopefully its not me :/

package.json
"gulp": "~3.5.2", "gulp-browserify": "^0.5.0", "debowerify": "^0.6.0", "browserify-shim": "^3.3.2" "browserify": { "transform": ["debowerify", "browserify-shim" ] }, "browserify-shim": { "./public/bower_components/jquery/dist/jquery.js": "$" },

My gulp task looks like this:

return gulp.src(INDEX_ENTRY_JS, {read: false}) .pipe(browserify({ debug: true, transform: ['debowerify','browserify-shim'] })) .pipe(size()) .pipe(require('gulp-rename')({suffix: "-bfy"})) .pipe(gulp.dest(OUTPUT_SCRIPTS)) .pipe(livereload(server));

Basically Im just hoping to get a simple window.$ to be defined. I cant seem to make it work.

Current error is:

Error: browserify-shim needs to be passed a proper browserify instance as the first argument. you passed:'PATH TO THINGS'

I've tried different versions and combinations of debowerify and this shim and none seem to work.

example update

in the documentation there's an example shows essentially how to shim jquery plugins:

{
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "browserify-shim": {
    "./vendor/x.js"    :  "$",
    "./vendor/x-ui.js" :  { "depends": [ "./vendor/x.js" ] }
  }
}

I'm assuming x.js is jquery in this case. However, the new version of the jquery library is available in npm, which added direct support for commonjs (2.1.x), and there's no longer a need to shim like this. How would it be done if $ is an existing npm module?

Paths not working without leading period

It seems like the paths in browser field aren't working without a leading period. Is this intentional? It seems to go against the standards of NPM main field, which works without a leading ./

I'm writing a small tool which generates browser fields from bower dependencies, and the normalized path won't always include the ./.

Support expose global config

I'm thinking of using the the backtick notation for this. As an example:

{
  "main": "./js/entry.js",
  "browser": {
    "jquery": "./js/vendor/jquery.js"
  },
  "browserify-shim": {
    "jquery": "$",
    "three":   "`THREE`"
  },
  "browserify": {
    "transform": [ "browserify-shim" ]
  },
  "dependencies": {
    "browserify-shim": "~3.0.0"
  }
}

would shim jquery as before, but since THREE is enclosed in backticks, it will replace all require('three') calls with window.THREE.

I hope this addresses the need expressed here.

Browserify-shim doesn't work with debowerify.

I just made an example of the issue.

  1. Clone https://gitlab.technocrata.com/templates/angularjs-bootstrap-browserify-sample.git
  2. Check "Build Preparation" on https://gitlab.technocrata.com/templates/angularjs-bootstrap-browserify-sample/tree/master
  3. After preparing build, execute "gulp dev" and connect to http://localhost:4000 on a web browser. You see a web page.
  4. Checkout browserify-shim branch.
  5. Execute "gulp dev" and connect to http://localhost:4000. You will see a broken web page which doesn't have angularjs loaded.
  6. Read package.json and the last commit on browserify-shim branch to start debugging the issue.

Compatibility with web workers

I am using browserify to create standalone modules that I can use in node.js and client side in browser. I don't use browserify on the entire app, just a few single node modules.

I do browserify-shim to shim e.g. lodash under the global var _. This works very well except when using the modules inside webworkers.

The problem is:

When I shim lodash as _ the browserified code sets var _ = window._, but windows is not defined inside the web workers.

I also posted the question on stackoverflow.com:
http://stackoverflow.com/questions/23395551/how-to-browserify-a-standalone-module-for-use-in-webworkers

jQuery gets included without explicit require()

Hi, I have set up browserify and added jQuery as a shim, but I don't understand why it is included into the the compiled js without being required explicitly.

Here's part of the Gruntfile:

browserify: {
  dist: {
    files: { 'dist/app.js': 'tmp/js/app.js' }
  , options: {
      debug: false
    , alias: 'tmp/js/app.js:myapp'
    , shim: {
        jquery: { path: 'bower_components/jquery/jquery.js', exports: '$' }
      }
    }
  }
}

Shims break with browserify noParse option

I'd like to be able to speed up my browserify processing time by using noParse on large shimmed dependencies. Unfortunately the shim itself depends on global which doesn't get added to the file unless it's parsed. causing the error...

Uncaught ReferenceError: global is not defined

I found another example of this issue here .

Can't browserify Ember.js

I am attemping to Browserify Ember.js using browserify-shim but every way I try when I run the browserify command Ember.js complains it can't find jQuery (on occasion will complain about handlebars instead probably a race condition).

I am thinking this might be a problem with browserify-shim but also might be browserify, ember.js or me being stupid.

I set up an example project here:
https://github.com/corbinu/browserify-ember

It simply pulls browserify-shim from NPM and Ember.js from Bower

when I run browserify . -d -o bundle.js

I get Error: module "jquery" not found from "/Users/$USER/browserify-ember/bower_components/ember/ember.js"

Any help would be appreciated.

Browserify v3

The current peer dependency for browserify prevents using v3. If you could update, then I'll be able to add Browserify v3 support to grunt-browserify. Thanks!

Error: module "0" not found

When using an external shim config, "depends": ["angular"] is converted to depends: { '0': 'angular' }. This leads to the following error:

{ [Error: module "0" not found from "/path/to/client/app/common/angular-resource/angular-resource.js"]
  filename: '0',
  parent: '/path/to/client/app/common/angular-resource/angular-resource.js' }
Error: module "0" not found from "/path/to/client/app/common/angular-resource/angular-resource.js"
  at notFound (/path/to/node_modules/browserify/index.js:811:15)
  at /path/to/node_modules/browserify/index.js:761:23
  at /path/to/node_modules/browserify/node_modules/browser-resolve/index.js:185:24
  at /path/to/node_modules/browserify/node_modules/resolve/lib/async.js:44:14
  at process (/path/to/node_modules/browserify/node_modules/resolve/lib/async.js:113:43)
  at /path/to/node_modules/browserify/node_modules/resolve/lib/async.js:122:21
  at load (/path/to/node_modules/browserify/node_modules/resolve/lib/async.js:54:43)
  at /path/to/node_modules/browserify/node_modules/resolve/lib/async.js:60:22
  at /path/to/node_modules/browserify/node_modules/resolve/lib/async.js:16:47
  at Object.oncomplete (fs.js:107:15)

npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

This was the output from BROWSERIFYSHIM_DIAGNOSTICS (BROWSERIFYSHIM_DIAGNOSTICS=1 browserify -d ./client/app/app.spec.coffee -o test.js). Note the depends: { '0': 'angular' } }:

{ file: '/path/to/client/app/app.spec.coffee',
  info:
   { package_json: '/path/to/package.json',
     packageDir: '/path/to/package',
     shim: undefined,
     exposeGlobals: {},
     browser:
      { angular: './client/app/common/angular/angular.js',
        'angular-cookies': './client/app/common/angular-cookies/angular-cookies.js',
        'angular-mocks': './client/app/common/angular-mocks/angular-mocks.js',
        'angular-resource': './client/app/common/angular-resource/angular-resource.js',
        'angular-route': './client/app/common/angular-route/angular-route.js' },
     'browserify-shim': './client/config/shim.js',
     dependencies: {} },
  messages:
   [ 'Found "angular" in browser field referencing "./client/app/common/angular/angular.js" and resolved it to "/path/to/client/app/common/angular/angular.js"',
     'Found "angular-cookies" in browser field referencing "./client/app/common/angular-cookies/angular-cookies.js" and resolved it to "/path/to/client/app/common/angular-cookies/angular-cookies.js"',
     'WARNING, depends "0" is not a path, nor is it exposed in the browser field, nor was it found in package dependencies.',
     'Found "angular-mocks" in browser field referencing "./client/app/common/angular-mocks/angular-mocks.js" and resolved it to "/path/to/client/app/common/angular-mocks/angular-mocks.js"',
     'WARNING, depends "0" is not a path, nor is it exposed in the browser field, nor was it found in package dependencies.',
     'Found "angular-resource" in browser field referencing "./client/app/common/angular-resource/angular-resource.js" and resolved it to "/path/to/client/app/common/angular-resource/angular-resource.js"',
     'WARNING, depends "0" is not a path, nor is it exposed in the browser field, nor was it found in package dependencies.',
     'Found "angular-route" in browser field referencing "./client/app/common/angular-route/angular-route.js" and resolved it to "/path/to/client/app/common/angular-route/angular-route.js"',
     'WARNING, depends "0" is not a path, nor is it exposed in the browser field, nor was it found in package dependencies.',
     { resolved:
        { '/path/to/client/app/common/angular/angular.js': { exports: undefined, depends: undefined },
          '/path/to/client/app/common/angular-cookies/angular-cookies.js':
           { exports: undefined,
             depends: { '0': 'angular' } },
          '/path/to/client/app/common/angular-mocks/angular-mocks.js':
           { exports: undefined,
             depends: { '0': 'angular' } },
          '/path/to/client/app/common/angular-resource/angular-resource.js':
           { exports: undefined,
             depends: { '0': 'angular' } },
          '/path/to/client/app/common/angular-route/angular-route.js':
           { exports: undefined,
             depends: { '0': 'angular' } } } } ] }

Here's my external shim config (./client/config/shim.js):

module.exports = {
  "angular": "angular",
  "angular-cookies": {
    "depends": ["angular"]
  },
  "angular-mocks": {
    "depends": ["angular"]
  },
  "angular-resource": {
    "depends": ["angular"]
  },
  "angular-route": {
    "depends": ["angular"]
  }
};

And here's my (relevant) package.json:

...
  "browserify": {
    "transform": [
      "coffeeify",
      "browserify-shim"
    ]
  },
  "browser": {
    "angular": "./client/app/common/angular/angular.js",
    "angular-cookies": "./client/app/common/angular-cookies/angular-cookies.js",
    "angular-mocks": "./client/app/common/angular-mocks/angular-mocks.js",
    "angular-resource": "./client/app/common/angular-resource/angular-resource.js",
    "angular-route": "./client/app/common/angular-route/angular-route.js"
  },
  "browserify-shim": "./client/config/shim.js",
...

When I move the shim config to inside package.json, browserify-shim is able to parse it properly:

{ file: '/path/to/client/app/app.spec.coffee',
  info:
   { package_json: '/path/to/package.json',
     packageDir: '/path/to/package',
     shim: undefined,
     exposeGlobals: {},
     browser:
      { angular: './client/app/common/angular/angular.js',
        'angular-cookies': './client/app/common/angular-cookies/angular-cookies.js',
        'angular-mocks': './client/app/common/angular-mocks/angular-mocks.js',
        'angular-resource': './client/app/common/angular-resource/angular-resource.js',
        'angular-route': './client/app/common/angular-route/angular-route.js' },
     'browserify-shim':
      { angular: 'angular',
        'angular-cookies': { depends: [ 'angular' ] },
        'angular-mocks': { depends: [ 'angular' ] },
        'angular-resource': { depends: [ 'angular' ] },
        'angular-route': { depends: [ 'angular' ] } },
     dependencies: {} },
  messages:
   [ 'Found "angular" in browser field referencing "./client/app/common/angular/angular.js" and resolved it to "/path/to/client/app/common/angular/angular.js"',
     'Found "angular-cookies" in browser field referencing "./client/app/common/angular-cookies/angular-cookies.js" and resolved it to "/path/to/client/app/common/angular-cookies/angular-cookies.js"',
     'Found depends "angular" exposed in browser field',
     'Found "angular-mocks" in browser field referencing "./client/app/common/angular-mocks/angular-mocks.js" and resolved it to "/path/to/client/app/common/angular-mocks/angular-mocks.js"',
     'Found depends "angular" exposed in browser field',
     'Found "angular-resource" in browser field referencing "./client/app/common/angular-resource/angular-resource.js" and resolved it to "/path/to/client/app/common/angular-resource/angular-resource.js"',
     'Found depends "angular" exposed in browser field',
     'Found "angular-route" in browser field referencing "./client/app/common/angular-route/angular-route.js" and resolved it to "/path/to/client/app/common/angular-route/angular-route.js"',
     'Found depends "angular" exposed in browser field',
     { resolved:
        { '/path/to/client/app/common/angular/angular.js': { exports: 'angular', depends: undefined },
          '/path/to/client/app/common/angular-cookies/angular-cookies.js': { exports: null, depends: { angular: null } },
          '/path/to/client/app/common/angular-mocks/angular-mocks.js': { exports: null, depends: { angular: null } },
          '/path/to/client/app/common/angular-resource/angular-resource.js': { exports: null, depends: { angular: null } },
          '/path/to/client/app/common/angular-route/angular-route.js': { exports: null, depends: { angular: null } } } } ] }

Modules defined in another module's `depends` configuration writes absolute paths to a bundle

From index.js#L19 it appears that this is intentional, but the effect is that a few scattered modules in my bundle contain the full filepath (including my user directory, etc.) in the source. This feels pretty messy and marks any depended modules with a full system path, meaning that builds will differ depending on who built them.

For example, my bundle has a lot of lines similar to this:

; jQuery = global.jQuery = require("/Users/samuelreed/git/project/app/ui/assets/js/libs/jquery.js");

Is there a different way we can go about this, perhaps by defining a project root and moving down the tree from there?

Shim not taking place using browserify .require?

I am attempting to require the 'restangular' module (for angularJS). My package.json contains (simplified):

"dependencies": {
  "angular": "~1.2.10",
  "lodash": "~2.4.1"
},
"browser": {
  "restangular": "./bower_components/restangular/dist/restangular.js"
},
"browserify": {
  "transform": ["browserify-shim"]
},
"browserify-shim" {
   "restangular": {
      "depends":  ["angular", "lodash:_"]
    }
}

If I run:

browserify -r restangular > bundle.js

then browserify-shim does not seem to excute. To test the shim, I created an abitrary file (test.js) and in it just placed:

require('restangular');

and upon runing:

browserify test.js > bundle.js

then browserify-shim performs as expected and requires both angular and lodash.

This issue is not occuring with any other shims I perform using the bundler require method of browserify. What is amiss here?

Parent and child share dependency

I can't seem to figure out how to write a reusable Angular module and app that both share the same Angular dependency. Both install Angular through bower and then refer to it in the package config:

{
  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browser": {
    "angular": "./app/bower_components/angular/angular.js",
    "angular-mocks": "./app/bower_components/angular-mocks/angular-mocks.js"
  },
  "browserify-shim": {
    "angular": "angular",
    "angular-mocks": {
      "depends": [
        "angular"
      ]
    }
  }
}

The module's config is essentially identical. How can I configure the child module so that it uses the Angular module brought in by the parent app?

Unable to shim bower modules.

I use debowerify to resolve bower modules.

browserify-shim prints errors when a bower module is depended on by browserify-shim.

Can you fix it?

Possible issue with certain path format

I'm using grunt-browserify which uses this to shim and when I specify the following shim:

'd3-chart-pie': {
  path: 'assets/bower_components/d3.chart.pie/lib/pie.js',
  exports: null,
  depends: {
    'd3-chart': 'd3-chart'
  }
}

I'm not sure why it fails, but it works when I take that config out. Here's the error:

SyntaxError: Unexpected string

Some more context here.

Ideas for browserify-shim v3

  • needs to be pure transform so it can be used without custom browserify build script
  • packages will have a "browserify-shimrc" (or similar) field in package.json which will point to shim config
  • package will also need to add browserify-shim to it's transforms
  • when browserify-shim is required it needs to resolve all requested shims ala sass-resolve

The idea is for packages to use shims and when used by other packages to ensure those get applied.
i.e. the dependent shouldn't need to know about what shims are defined in modules it depends on.

Another major point is to allow defining all that is needed via the package.json which is currently possible for most other browserify features.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.