nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.48k stars 284 forks source link

Uncaught reference error: require is not defined #102

Closed ShaunodCIT closed 8 years ago

ShaunodCIT commented 8 years ago

Simply as the title says. I'm calling the require() function in my code and the error "Uncaught reference error: require is not define" is being displayed in the console.

Does anyone know what could possible cause this? I'll include links to my code if needs be.

Thank you.

EDITS: Node v5.5.0 OS: Windows 7 Ultimate Language: Javascript

joshmanders commented 8 years ago

Include any relevant information such as what version of node, operating system, code, etc.

ShaunodCIT commented 8 years ago

Edits made. Thanks.

joshmanders commented 8 years ago

Can you please provide the code that is causing errors?

joshmanders commented 8 years ago

Aso is this in your terminal console or browser console you're getting this error?

ShaunodCIT commented 8 years ago

This is the one line that is causing it: var klapi = require('./klapi.js');

This error is appearing in my browser console.

joshmanders commented 8 years ago

Node.js is for the server side. Browsers do not implement require. For that to work you need to bundle your code with either Browserify or Webpack.

ShaunodCIT commented 8 years ago

I have tried doing that and it has resulted in the same error. Is there any other way, other than require(), to do what I'm trying to do?

joshmanders commented 8 years ago

I really can't help with any more than that without code showing what you're trying to do. Browserify and Webpack are used by thousands of people a day, they work. I use require in the browser because of these tools.

megastef commented 8 years ago

Maybe this is helpful: