If you're in a Browser-Only environment, use SridharR's solution.
If you're in a Node/CommonJS + Browser environment (e.g. electron, node-webkit, etc..); the reason for this error is that jQuery's export logic first checks for module
, not window
:
if (typeof module === "object" && typeof module.exports === "object") {
// CommonJS/Node
} else {
// window
}
Note that it exports itself via module.exports
in this case; so jQuery
and $
are not assigned to window
.
So to resolve this, instead of <script src="path/to/jquery.js"></script>
;
Simply assign it yourself by a require
statement:
<script>
window.jQuery = window.$ = require('jquery');
</script>
NOTE: If your electron app does not need nodeIntegration
, set it to false
so you won't need this workaround.