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)

cdarwin
  • 4,141
  • 9
  • 42
  • 66

2 Answers2

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!

Anand G
  • 3,130
  • 1
  • 22
  • 28
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");
h.aittamaa
  • 329
  • 3
  • 4