thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
933 stars 87 forks source link

Shim export line not being added to certain files #116

Closed gabrielecirulli closed 9 years ago

gabrielecirulli commented 9 years ago

I have a browserify setup where I can shim bower modules (also using shimbro).

I've installed headroom.js through bower and added the following fields to package.json:

{
  "browserify": {
    "transform": [
      "6to5-browserify",
      "browserify-shim"
    ]
  },
  "browserify-shim": {
    "headroom": "Headroom"
  },
  "browser": {
    "headroom": "./bower_components/headroom.js/dist/headroom.js"
  }
}

For some reason, no matter what I do, the line

; browserify_shim__define__module__export__(typeof Headroom != "undefined" ? Headroom : window.Headroom);

won't be added to the bottom of the file, no matter what.

To be clear, looking in the bundled result the file is present in full (because I required it in my application code), but the module export line is not there.


Also, at some point while I was trying to fix it, the line was there but requiring the file was returning an empty object. Even placing console.log calls in the source file printing window.Headroom were showing the expected object, but it wasn't being exported at all.


I can do without Headroom for the time being but this problem is quite unsettling because I couldn't figure out what was happening and more importantly why.

Am I doing something wrong?

hesalx commented 9 years ago

It may depends on how you actually build the bundle. I have a lot of issues while trying some things to play well together. There were just configuration misconceptions.

For example, if you require some module in a browserify pipeline manually, it won't be shimmed automatically, unless you explicitly add a transform with the browserify-shim module to the pipeline.

If you provide your build scripts (gulp/grunt) or the command you run, it may help the community to figure out the problem.

bendrucker commented 9 years ago

We need a reproducible example to look at this

gabrielecirulli commented 9 years ago

Sorry for the lack of response. I ended up removing that library from my code, and haven't had problems with browserify-shim since. I think we can close this.

bendrucker commented 9 years ago

No worries. Doesn't sound like a b-shim issue to me. Cheers!