Javascript error : Uncaught ReferenceError: require is not defined

北城以北 提交于 2019-12-19 10:22:18

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/45723462/javascript-error-uncaught-referenceerror-require-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!