0

Please pardon my lack of knowledge on js bundling but I would like to import this javascript file into my Vue.js project and use its function and I just can't see to get it to work.

https://github.com/omnisci/Charting-Sample/blob/master/main.js

Maybe this is just something fundamental about how the file was bundled but I am trying to import it like this

import * as omni from "../main";

and then trying to use a function from the file like this

omni.crossfilter.crossfilter(con, tableName)

But I am getting this error

Uncaught TypeError: _omni__WEBPACK_IMPORTED_MODULE_1__.crossfilter is not a function

When I just include the file in regular html file using a src and script tag it works just fine calling the function. If anyone could give me some guidance on what I am doing wrong here, or how to import this properly I would really appreciate it.

Paradom
  • 73
  • 2
  • 9
  • have you tried `import omni from "../omni"`? Might sometimes also be `import { omni } from "../omni"` – A. L May 19 '20 at 01:15
  • https://stackoverflow.com/questions/48426972/importing-javascript-file-for-use-within-vue-component This may help you. – Jake Lam May 19 '20 at 02:20
  • It also depends on how you exported your function from main.js. Can you also add your omni snippet? – Abhinab Rajopadhyaya May 19 '20 at 17:40
  • This is the file that the functions are exported in. I didn't write it so I was not sure if it would even work with vue. https://github.com/omnisci/Charting-Sample/blob/master/main.js – Paradom May 19 '20 at 17:52

1 Answers1

0

Just write:

import '../main'

and call functions after import:

/ ...
crossfilter(con, tableName)
Hans Felix Ramos
  • 4,264
  • 3
  • 16
  • 40
  • This is still telling me "error 'crossfilter' is not defined". I edited my question so that it is more clear what I am importing. (I had renamed the file main.js to omni.js) – Paradom May 19 '20 at 16:57
  • The minified file just generate global variables. Try to console.log(crossFilter) after import to check it. – Hans Felix Ramos May 19 '20 at 19:15