0

I would like to use this library (https://github.com/riichard/boolean-parser-js) (which is really just a function?) in my own project.

My project is contained in a single html file. In one of the functions, I've tried including the following:

var parser = require('boolean-parser');

I get the following error when I include this.

Uncaught ReferenceError: require is not defined

I have installed the library via the terminal, using "npm install boolean-parser". At the same level as my project, I see a file called "node_modules", which contains "boolean-parser".

I'm not sure if this is the right method of referring to the library... I'm also not sure how to find out what it.

If possible, please explain terminology in your answer(s)-- I have limited background knowledge in this area, as this is essentially my first real web project!

Happy to include code upon request. Feel free to suggest tag additions!

P.S. Could it be a file path problem? Do I need to use something like Browserify?

P.P.S. If I include

<script src="node_modules/boolean-parser/index.js"></script>

then it seems like the library is working, but then I get an error from within it:

index.js:295 Uncaught ReferenceError: module is not defined at index.js:295

2 Answers2

1

It is because you are making client side project. Here is related question link

Dauren
  • 36
  • 4
  • Thanks a bunch! I assume the most straightforward solution is to include the file using script tags? If so, I've tried this, and I'm having trouble with the file path. Seems like the library is working but not a module within it, and maybe I shouldn't refer directly to the index file-- any suggestions here? – Biffsquiggle Jun 01 '18 at 16:45
  • Which functions do you need ? Maybe you can just copy them straight to you page ? – Dauren Jun 01 '18 at 16:57
  • Thanks for your suggestions! I could... I'd rather keep them as separate files. Using as the path, I get the same "require is not defined" error! I'm just not sure which .js within the library I should be referring to... this is kinda a new question, so I might post it as such. Edit: Actually, I can't post a new question yet-- so any responses would be greatly appreciated! – Biffsquiggle Jun 01 '18 at 17:10
  • Okay, update: I think I've determined I need the index.js file-- but when referring to this, I get: _Uncaught ReferenceError: module is not defined_ – Biffsquiggle Jun 01 '18 at 17:17
  • Easiest way is: change 'module.exports' to 'window.module' in index.js. In your html page you can access this functions through window.module. – Dauren Jun 01 '18 at 17:38
  • Do you mean I should do this and still use script tags to reference the index file? I changed to: Window.module = { deduplicateOr: deduplicateOr, ... }; I still get the same error: _module is not defined_ – Biffsquiggle Jun 01 '18 at 18:21
  • Yes, you still need use script tag for index.js – Dauren Jun 01 '18 at 18:23
  • Okay, I did that, still get the same error: _module is not defined_. – Biffsquiggle Jun 01 '18 at 18:26
  • Check again your script tag – Dauren Jun 01 '18 at 18:44
  • ? This seems correct, because now the error refers to module, which is in the index file. I've included the entire function in the main file, for now, to avoid the error, but I'm still interested in the answer... – Biffsquiggle Jun 01 '18 at 18:55
0

Listen, i created simple html page with 2 script tags. First contains src="index.js" which is in the same folder and edited as i said before. Second script tags is:

<script>
  console.log(window.module):
</script>

And everything works. Check yourself again.

Dauren
  • 36
  • 4
  • Please be patient with me-- I'm not familiar with these languages yet. I get the same error if I add both script tags. A few questions: Is the purpose of the second one to check if Window.module exists? If so, I'm seeing 'undefined'. Should window be capitalized in all instances? – Biffsquiggle Jun 01 '18 at 19:36