I have a basic program in node.js, where I run:
npm install ml5
This installs ml5 version 0.3.1
When I try to require it in my program with:
cont ml5 = require('ml5');
I get an error:
(function (exports, require, module, __filename, __dirname) { !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ml5=e():t.ml5=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/",n(n.s=698)}([function(t,e,n){"use strict";n.r(e),function(t,r,i,a){n.d(e,"AdadeltaOptimizer",function(){return ml}),n.d(e,"AdagradOptimize
ReferenceError: window is not defined
at Object.
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.
at Module._compile (module.js:652:30)
Tenho o mesmo problema. Estou estudando node.js, tensorflow, ml5, etc... pelo que entendi, esse framework ml5 foi criado para rodar diretamente no browser. Tanto 茅 que o objeto BOM window 茅 invocado dentro do ml5.min.js. Se criar um js e rodar a partir de um html vai funcionar.
@oveddan - Thanks for raising this issue. I've added this to the list of todos for the next coming weeks/months. I'd love for ml5 to be more flexible in this regard.
Right now we have issues with supporting ml5 as a npm module and can only really be used via the CDN link. This has to do with calls to the window object that I think might be causing any bundling to break.
You've also mentioned how awesome it would be to be able to choose specific ml5 features (e.g. to be able to do npm install ml5/bodypix). This is a super nice suggestion and am all for it.
If you've got ideas for how we might move this forward, I'm all ears and happy to support.
In the meantime, we should def. do our best to make sure ml5 doesn't break in other environments!
Thank you!
@samuelrosacv muito obrigado pra sua messagem. (meu portugeus nao e bom, mas posso falo um poco). Nos esperamos resolver esse "issue" estes proximos semanas.
Obrigadao!
Would love if you could please get it working with Node as well. Thanks!
Any solution yet?
I'm using Nextjs, React and ml5 (v - 0.5) node module and the window error is still here
@joeyklee , any solution?
In Next.js project with import * as ml5 from 'ml5' same issue.
Hi @Prottoy2938 and @srcnalt - Thanks for your comments here. The changes required here are on our roadmap, but I can't say for sure when this will be resolved. I wish I could give you a better timeline for this, but for the time being there has not been any progress here.
The way ml5 is structured at the moment makes calls the window that cause it to fail in the contexts you're attempting to use the library in. Sorry!
Thank you for the reply @joeyklee meanwhile I was able to get it working using react hooks, hope it helps others who have the same issue.
//global
let ml5: any
//in component
useEffect(() => {
ml5 = require('ml5')
}, [])
Most helpful comment
Would love if you could please get it working with Node as well. Thanks!