Installing a library with JS
Hello,
I'm trying to build a demo bar code scanner. I found this library:
https://serratus.github.io/quaggaJS/#node-example
I've installed Node + Quagga (library)
My dependencies are the following:
However, when running test script (provided in docs), I get this error
ReferenceError: require is not defined
at scan.js:71:14
which makes me believe I've installed wrong. Any ideas how to fix this?
Sample script ran:
QuaggaJS, an advanced barcode-reader written in JavaScript
QuaggaJS is an advanced barcode-reader written in JavaScript
18 Replies
did you run npm install in your project folder?
Yes I did. My script tag also has module attribute
oh, i tested it with this in the first line and it worked, maybe try it
var Quagga = require('quagga').default;
Same issue
Which commands did you run?
@Heitor is this because I'm running node in browser without express?
not sure, I installed the library with npm, created a file index.js with the example and ran "node index.js" in the terminal
Hmm
I'm lost right now keep getting this error
ReferenceError: document is not defined
when running node scan.js
I have node
GeeksforGeeks
How to run Node Server ? - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Following these exact commands + sample code still gives me errors
maybe try changing the require to ES6 module import
import Quagga from 'quagga';
@Heitor What npm commands did you run?
just
npm i quagga
and before i started the project, with npm init -y
hmm
ive no idea lol
do you have node isntalled?
yeah i have node, not sure what is happening there, sorry i could not help much 😕
No worries!
Thank you @Heitor
@Matt quagga is a browser library per its readme so your issue makes sense. Your error gives it away: any time you see a mention of
document
not existing you are definitely trying to run something written for browser (where there's a document
global e.g. document.querySelector("#heroSection")
) in a server-side environment (like NodeJS) where no such thing exists. Hence the error: code is trying to reference it and its not defined.