admin管理员组文章数量:1401640
I installed jQuery and it is not my question:
npm install jquery
I try to include jQuery library into my page like this:
var jQuery = require('jquery'); or
import jQuery from "jquery";
and get in Chrome console:
Uncaught ReferenceError: $ is not defined
How can I overe it?
I installed jQuery and it is not my question:
npm install jquery
I try to include jQuery library into my page like this:
var jQuery = require('jquery'); or
import jQuery from "jquery";
and get in Chrome console:
Uncaught ReferenceError: $ is not defined
How can I overe it?
Share Improve this question edited Jul 27, 2017 at 12:03 asked Jul 27, 2017 at 7:18 user5965280user5965280 2- 1 Possible duplicate of Can I use jQuery with Node.js? – eisbehr Commented Jul 27, 2017 at 7:20
-
Did you try
import {jQuery, $} from "jquery";
? – 31piy Commented Jul 27, 2017 at 7:24
2 Answers
Reset to default 6You have to use:
var $ = require('jquery');
or
import $ from 'jquery';
In my cases the following works well:
global.jQuery = require('jquery');
global.$ = global.jQuery;
or if you prefer "window" or it is obviously present, then:
typeof window !== "undefined" ? window : this;
window.jQuery = require('jquery');
window.$ = window.jQuery;
版权声明:本文标题:javascript - Nodejs Uncaught ReferenceError: $ is not defined after var jQuery = require('jquery'); - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744261843a2597754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论