https://github.com/mlms13/shim-bug
https://github.com/mlms13/shim-bug
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mlms13/shim-bug
- Owner: mlms13
- Created: 2014-05-30T23:25:21.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-31T14:50:46.000Z (about 12 years ago)
- Last Synced: 2025-06-07T03:05:58.517Z (about 1 year ago)
- Language: JavaScript
- Size: 164 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A bug in [browserify-shim](https://github.com/thlorenz/browserify-shim)?
When you use browserify-shim to make a library available globally -- let's say jQuery -- the global library isn't available inside the node_modules folder for modules that contain their own package.json.
For example, given the following structure (which is pretty close to the structure if this repo):
```
node_modules/
foo/
index.js
package.json
app.js
jquery.js
package.json
```
Assume that inside the main `./package.json` we have browserify and browserify-shim set up as follows:
```
"browser": {
"jquery": "./assets/jquery.js"
},
"browserify": {
"transform": ["browserify-shim"]
},
"browserify-shim": {
"jquery": "$"
}
```
You would expect `require('jquery')` to just work, thanks to the shim. And it does, inside `app.js`. But if `app.js` requires `foo` (which lives inside the node_modules folder), and `foo` includes a `require('jquery')`, browserify won't use the globally shimmed `jquery`.
If you remove `node_modules/foo/package.json`, browserify will complete successfully. But as soon as the `foo` module has its own `package.json`, it loses access to the shimmed `jquery`.
## To test
Clone this repository:
`git clone https://github.com/mlms13/shim-bug.git`
Install dependencies (browserify and browserify-shim)
`npm install`
With browserify installed globally, try to run the following:
`browserify index.js -o bundle.js`
You should see an error along the lines of `Error: module "jquery" not found from "/Users//Projects/shim-bug/node_modules/foo/index.js"`
If you delete `node_modules/foo/package.json` and re-run the `browserify` command, everything should work as expected.