I'm using the sublime text 3 editor
Error is the following
The loading of jquery reference should be correct..
Is like this on file.haml
%script{ :src => "js/jquery-3.3.1.min.js" , :type => "text/javascript"}
%script{ :src => "js/jquery-ui.min.js" , :type => "text/javascript"}
%script{ :src => "js/submitEvent.js" , :type => "text/javascript"}
My file.js works the same on my webpage but, if i try to build it ...give this error
can someone explain to me why?
/home/utexm/Scrivania/Testing-20/customForm/js/submitEvent.js:1
(function (exports, require, module, __filename, __dirname) { $(document).ready(function(){
^
ReferenceError: $ is not defined
at Object.<anonymous> (/home/utexm/Scrivania/Testing-20/customForm/js/submitEvent.js:1:63)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
[Finished in 0.1s with exit code 1]
[cmd: ['/usr/bin/node', '/home/utexm/Scrivania/Testing-20/customForm/js/submitEvent.js']]
[dir: /home/utexm/Scrivania/Testing-20/customForm/js]
[path: /usr/local/bin:/usr/local/sbin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/node_moduler/bin/]
A website uses jQuery differently than Node does. In the browser, jQuery is assigned to global variable (
jQuery
/$
). Node usesrequire()
or ES6imports
to make jQuery accessible in a script.If you need your code to run in both, Node and the browser, you need to use a bundler such as Webpack or Browserify. However, to expains these is beyond the scope of your question. I'd start by reading a tutorial and come back when you have specific questions along the way.