Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import jQuery from a file using es6

Due to this project idiosyncrasies I need to import jQuery into my main.js using a direct path that is not in the node_modules folder but I am not able to do it. All the questions I have found points to jquery that lives in node_modules

I have this

import {MyModule} from './components/myModule.js';
import jQuery from './jquery/jquery-3.3.1.js';

MyModule works as expected (on Chrome) but jQuery yields:

Uncaught SyntaxError: The requested module does not provide an export named 'default'

jquery-3.3.1.js is the uncompressed, development jQuery 3.3.1 version from jQuery.com, I have also tried with the production version.

How should I import it?

Edit:

This is NOT a duplicate of How to import jquery using ES6 syntax?. Because import {$,jQuery} from 'jquery'; searches on node_modules and when I import it from the given path I get the error quoted above.

like image 537
distante Avatar asked Feb 07 '18 07:02

distante


1 Answers

You should use:

import * as jQuery from './jquery/jquery-3.3.1.js'

Documentation about the import statement: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/import

like image 75
F_Mekk Avatar answered Sep 28 '22 01:09

F_Mekk