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 email@example.com
error '$' is not defined
After spending some time on this, here are my observations:
firstname.lastname@example.org, throws the following warning:
npm WARN deprecated email@example.com: 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 firstname.lastname@example.org. 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.