0

Beginer at coffeescript. I installed coffee-script and socket.io by npm. But this simple code shows me an error:

try
  io = require('socket.io')
catch error
  alert(error)

it returns require is no defined. Same problem with other modules (for example fs). Using PyCharm

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
Axel
  • 1
  • 1
  • 2
    Possible duplicate of [Node.js - require is not defined exception](http://stackoverflow.com/questions/8404562/node-js-require-is-not-defined-exception) – Christos Papoulas Nov 07 '15 at 12:32
  • How are you running your code? `require` only works in CommonJS environment (i.e. in `node.js`). You're not trying to run this code in a browser, are you? – Leonid Beschastny Nov 07 '15 at 13:26
  • Oh shi... But how can i use socket.io on client side for communicate with backend on Flask? – Axel Nov 07 '15 at 14:25
  • Use socket.io-client – Tomasz Jakub Rup Nov 07 '15 at 15:01
  • But for use socket.io-client i need to call require('socket.io-client'). Am i right? How can i use other modules in coffee-script expect require() function? – Axel Nov 07 '15 at 15:20
  • You can use `socket.io-client` without `requirejs`, but I recommend to learn `requirejs`. – Tomasz Jakub Rup Nov 07 '15 at 16:39
  • Well, you could load `socket.io-client` script in an old way, using separate ` – Leonid Beschastny Nov 07 '15 at 21:31

0 Answers0