pboyer/verb

Problem with header for verb for JavaScript

elifer5000 opened this issue · 1 comments

I think this check in the verb.js header, is not correct

// node.js context, but not WebWorker
if ( typeof window !== 'object' && typeof require === "function"){
    Worker = require('webworker-threads').Worker;
}

Try opening one of your examples, like http://verbnurbs.com/examples/curveClosestPoint.html
and set a breakpoint there. You can see that window is not defined, even though we are in the browser. Furthermore, it is defined one step above in the call stack.

This makes it think that it's in a node context. In this case nothing happens, because require is not defined. But if you use verb inside a library that it's browserified, require will be defined, and it will require webworker-threads, which creates further problems (browserify won't work if it's not installed, and if you do install it, it will fail at runtime since it's not meant to run in the browser)

In conclusion, either the check is not correct, or window should somehow be defined there when running from a browser.

@elifer5000 Thanks a lot for letting me know. This should be fixed in 2.0.2 - out now. Just give it a npm install.