fgnass / spin.js

A spinning activity indicator
http://spin.js.org
MIT License
9.3k stars 1.02k forks source link

Error when running in node.js: document not defined #251

Closed mearns closed 9 years ago

mearns commented 9 years ago

I tried to use the spin module in a simple script in node.js, and got an error. Here is the script (test.js):

require('spin');

And the error:

C:\Users\bmearns\node_modules\spin\spin.js:16
  var el = document.createElement(tag || 'div');
           ^
ReferenceError: document is not defined
    at createEl (C:\Users\bmearns\node_modules\spin\spin.js:16:12)
    at C:\Users\bmearns\node_modules\spin\spin.js:39:12
    at Object.<anonymous> (C:\Users\bmearns\node_modules\spin\spin.js:42:2)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\Users\bmearns\test.js:3:1)

I'm using node v0.10.25, and spin version 1.2.5, installed with npm.

mearns commented 9 years ago

Tried again with latest node, node v0.10.32, and the same results.

fgnass commented 9 years ago

That's the expected behaviour since spin.js requires a DOM. It's published as npm module so that you can use it with tools like browserify.

mearns commented 9 years ago

Ok, thanks. I'm new to using node and the rest, so I assumed that having a npm module means that it's supposed to work with node from the command line. Thanks for clarifying!