Возвышенная проблема сборки текста 3 Haml/jQuery $ не определена
Я использую редактор возвышенного текста 3
Ошибка заключается в следующем
Загрузка ссылки jquery должна быть правильной.
Это как на 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"}
Мой file.js работает так же на моей веб-странице, но, если я попытаюсь собрать его... выдайте эту ошибку
может кто-нибудь объяснить мне, почему?
/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/]
1 ответ
Решение
Сайт использует jQuery иначе, чем Node. В браузере jQuery назначается глобальной переменной (jQuery
/ $
). Узел использует require()
или ES6 imports
сделать jQuery доступным в скрипте.
Если вам нужно, чтобы ваш код работал как в Node, так и в браузере, вам нужно использовать такой пакет, как Webpack или Browserify. Тем не менее, до истины это выходит за рамки вашего вопроса. Я бы начал с прочтения учебника и вернулся, когда у вас возникнут конкретные вопросы.