Quote:
I refresh browser and get ERROR REQUIRE IS NOT DEFINED
That is because by default a browser does not know what a require method is supposed to do. There are of course various methods by which you can give the browser an idea of what a
require
call would do.
Side note, the
require
calls were popularized by Node.js, and Node.js works on the backend in a special process that knows the Node.js API and what methods mean in its context. So, the code that works just fine in a Node.js app, would most likely never work in a browser.
Your best bet would be to avoid using the
require
call, and try to inject the require.js directly with a script tag. Visit
this website for require.js[
^], and download the script. Once done, you can then link the script using the
script
tag in the HTML document;
read the page that I have linked.
If you still wish to use this — maybe the tutorial is using, or maybe the app code uses require too much — then consider converting this code to the browser-understandable one. Webpack, browserify, etc. are a few of the examples that convert this kind of JavaScript (which is standard in a context, and ambiguous in another...) to a standard JavaScript that can work in a browser.
Read the following:
https://webpack.js.org/[
^]
javascript - Client on Node.js: Uncaught ReferenceError: require is not defined - Stack Overflow[
^]
Browserify[
^]
Free tip: never assume that the code that works on your machine would work on your client's machine. They might have a totally different setup and would never be interested in downloading/installing plugins for you. If in the first 5 seconds (a very optimistic number) your website does not show a good page, they'll leave the website considering it as a broken page.