0

I'm running the following code from a test.js file using babel-node from the command line: babel-node test.js

installing jquery

npm i --save jquery

test.js:

import $ from 'jquery';

$.get("www.google.com");

I get TypeError: _jquery2.default.get is not a function

Any suggestion?

Please note that this question is not a duplicate of How to import jquery using ES6 syntax?, because this seems a problem specific to babel-node (the same code works if I create a bundle using webpack with babel and run it from a browser)

2 Answers 2

0

Your import should be import * as $ from 'jquery';

Also it most likely a conflict of $. Try adding

 var jq = $.noConflict();
 jq.get("www.google.com");

Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

I keep getting TypeError: $.get is not a function
Its most likely a conflict issue, add $.noConflict(); in script tag, Read more here api.jquery.com/jquery.noconflict
Unfortunately I get TypeError: _jquery2.default.noConflict is not a function
0

To get it it work with NodeJS, jQuery must be executed in dom context. Modules like domJS can do the job othewise if you need making ajax request. The best choice is using other specific modules like "https" or "request" like the example bellow :

import https from 'https';
https.get("https://www.google.com");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.