I am facing a cryptic issue with Browserify regarding jQuery plugins. Since I have several packages for individual sub-applications, I have some global libraries as <script> tags in my HTML to prevent repetition.
I use gulp , browserify-shim and babelify to create my packages.
Inside package.json :
"dependencies": { "jquery.cookie": "^1.4.1", ... }, "browserify-shim": { "jquery": "global:jQuery", ... }, "browserify": { "transform": [ "browserify-shim" ] }
Inside base.html : (During creation, these will be CDN links)
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
In one of my source files:
import $ from 'jquery'; // this works import 'jquery.cookie'; // this crashes browserify
Error message:
Error: Cannot find module 'jquery' from '/path/to/node_modules/jquery.cookie'
jQuery is not installed with npm number since I do not want it to be rolled into my packages.
I assume the problem here is that in jquery.cookie.js there is a call to require('jquery') that is not resolved.
How can I "fake" the existence of a global jQuery instance for a plugin using a pad browser?
NB: This solution does not meet my needs, since jQuery will be collapsed into many packages.
source share