-1

I have an openlayers with online jquery working, but sometimes I won't have internet access and I'd like to use it offline. I've downloaded the lib but it's not working, I'm sure that it's in the "js" folder, please help me

I'm using nodejs and openlayers

//working
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">   
<script src="js/bootstrap.min.js"></script>

//not working 
<script src="js/jquery-3.4.1.min.js"></script>    
<link rel="stylesheet" href="css/bootstrap.min.css">   
<script src="js/bootstrap.min.js"></script>

//browser error
Error: Bootstrap's JavaScript requires jQuery bootstrap.min.js:6:36
ReferenceError: $ is not defined

​it's giving me this error, but with online jquery it's OK

Adm
  • 37
  • 8

2 Answers2

1

First of all you should install jQuery. Run command below in your project folder to install jQuery:

npm install jquery

You should import it in index.js file:

import {$,jQuery} from 'jquery';
// export for others scripts to use
window.$ = $;
window.jQuery = jQuery;

Based on this post.

Or you should import it to your html:

<script src="node_modules/jquery/dist/jquery.min.js"></script>

If you find the right answer please close the question on other communities(r.g. gis.stackexchange.com) and refer to the answer. Thanks!

Hope it helps.

Mahdi Mahmoodian
  • 473
  • 2
  • 13
  • thaks for the answer, but none of this solutions worked. why using the online jquery works fine? is strange, but for me it's not a solution, I need it offline – Adm Oct 22 '19 at 13:14
  • Are you sure it installed? if it's installed where is your index.html? you have to import it with a local path. put your index.html in the root of project(next to node_modules). then use `node_modules/jquery/dist/jquery.min.js` to import – Mahdi Mahmoodian Oct 22 '19 at 22:46
0

I just solved using a local server, don't ask me why it works this way and junt pointing the file path didn't work

first, open a terminal and go to the jquery.min.js folder, then start a simple server (ex: python3 -m http.server 8080)

after, go to the index. html file and add the source

<script src="http://localhost:8080/jquery-3.4.1.min.js"></script>

and now it works offline

Adm
  • 37
  • 8