frenchtoast747 / webgl-obj-loader

A simple OBJ model loader to help facilitate the learning of WebGL.
http://frenchtoast747.github.io/webgl-obj-loader/
MIT License
282 stars 59 forks source link

'window' is not defined in node.js #63

Closed maierfelix closed 5 years ago

maierfelix commented 5 years ago

I'm using .mjs in my node.js project and I import the loader with:

import OBJ from "webgl-obj-loader";

But when importing I get the error that window is undefined in webgl-obj-loader.min.js. I fixed it by replacing window with: typeof window !== "undefined" ? window : global.

I'm not sure if that is the right fix to use this project in node, I can create a PR if it's fine

frenchtoast747 commented 5 years ago

Thanks for pointing this out!I'll take a look and try to get a fix in ASAP!

maierfelix commented 5 years ago

ping, hello world

frenchtoast747 commented 5 years ago

I'm so sorry, I completely forgot about this issue. I'm looking at it right now!

frenchtoast747 commented 5 years ago

Apparently it was a problem with Webpack's umd output. This was fixed in 83ce2d5e0affceab31997a4bea9d8d8eb8da8bef by adding

output: {
// ...
globalObject: "typeof self !== 'undefined' ? self : this",
// ...
}

In the webpack config.