thlorenz / browserify-shim

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

Cannot set a dependency to global #179

Closed vamsiampolu closed 9 years ago

vamsiampolu commented 9 years ago
 "browserify-shim":{
     "google":{
       "exports":"global:google"
     }
  },

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

I use this command with the above config:

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

I get this error:

Error: Cannot find module 'google' from 'C:\Users\lenovo\Downloads\Browserify\Browserify\js\leaflet-plugins'

at %global_browserify_install_path%\node_modules\resolve\lib\async.js:46:17
at process (%global_browserify_install_path%\node_modules\resolve\lib\async.js:173:43)
at ondir (%global_browserify_install_path%\node_modules\resolve\lib\async.js:188:17)
at load (%global_browserify_install_path%\node_modules\resolve\lib\async.js:69:43)
at onex (%global_browserify_install_path%\node_modules\resolve\lib\async.js:92:31)
at %global_browserify_install_path%\node_modules\resolve\lib\async.js:22:47
at FSReqWrap.oncomplete (fs.js:95:15)

I am using 32 bit Windows 7 with the babun shell.

I use it like this:

"L.Google": {
  "depends": [
    "leaflet:L",
    "google"
  ]
}

I have tried removing the

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

instead using the

  BROWSERIFYSHIM_DIAGNOSTICS=1 browserify ./js/btest.js -t browserify-shim -o bundle.js

This approach worked for a toy project where I was just doing:

  var google = require('google');

but it does not work when I am trying to use google as a dependency,it does recognize the need to:

exposeGlobals: { google: 'google' }

bendrucker commented 9 years ago

That's because you only use exports when specifying an external shim:

https://github.com/thlorenz/browserify-shim#2a-add-expose-global-config-to-external-shim-config

If that's not the issue here, please create a reproduction with no dependencies other than browserify/b-shim that we can clone and test so we can reopen.