Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript error : Uncaught ReferenceError: require is not defined

I making a regster form in HTML, with javascript. I Have file Login.js. My browser says the following error: Uncaught ReferenceError: require is not defined.enter image description here

like image 683
isaque Avatar asked Jan 04 '23 14:01

isaque


2 Answers

require is a way for different compilers to put in stuff that is needed, later on, while keeping the file small. Did you copy the js file from somewhere else?

You may need to include http://requirejs.org/

Also, this looks incredibly insecure. Are you planning to release this site to the word? or is it just for class/experiment?

As the one comment mentions, if this is supposed to be server-side code, it's not going to work very well on the client side.

like image 92
Adam Pine Avatar answered Jan 06 '23 04:01

Adam Pine


require is defined in Node.js. Browsers don't have definition for require.

You need to use node module browserify to compile code that uses require for browsers.

Alternatively you can use RequireJS which is file and module loader for browsers.

And remember that normally you can't access files on your disk with javascript due to security reasons.

like image 42
Tymski Avatar answered Jan 06 '23 04:01

Tymski