I'm writing a react app that will live inside of a webpage that already contains jquery. This means I need global access to jQuery during development, but do not want to include it with the bundle on build ( since jquery will already exist on the page where it is deployed ).
I'm having difficulty getting jquery as a global ( aka accessible from anywhere via
npm install firstname.lastname@example.org
error '$' is not defined
After spending some time on this, here are my observations:
email@example.com, throws the following warning:
npm WARN deprecated firstname.lastname@example.org: Versions of the jquery npm package older than 1.9.0 are patched versions that don't work in web browsers. Please upgrade to >=1.11.0..
Trying to build my bundles using this version of
jquery completely fails. I don't know how you did it, but for me it fails. I am using
I checked the source code of the
jquery downloaded with
npm install email@example.com. It is definitely modified from the original source. The original source code still exists though under
Your best bet for this to work is by doing this, at some point before the rest of your code:
This way the file will be executed,
jquery will be registered to
window, as originally intended, and you can use
$ in the rest of your code.