[英]is not a function in electron chrome but not node console
我在电子项目中使用的npm包, foreach批次 。 我已经安装了软件包, Cannot find module
错误。
var forEachBatch = require('foreach-batch')
var stuff = [0,1,2,3,4,5,6,7,8,9]
forEachBatch(stuff, function(i) { console.log(i) }, 2, function(progress) {
console.log(progress);
}, 1000);
该代码按预期在节点控制台中运行
$ node
> var forEachBatch = require('foreach-batch')
undefined
> var stuff = [0,1,2,3,4,5,6,7,8,9]
undefined
>
> forEachBatch(stuff, function(i) { console.log(i) }, 2, function(progress) {
... console.log(progress);
... }, 1000);
0
1
0.2
...
但是,当我以npm start
电子并在chrome控制台中输入相同的代码时。 我收到Uncaught TypeError: forEachBatch is not a function
我是Node and Electron的新手,任何能帮助我更好地理解体系结构的见解都将受到赞赏。
该模块在浏览器中不返回任何内容。
一点代码
var forEachBatch = function() { .... };
window.forEachBatch = forEachBatch;
所以当你这样做
var forEachBatch = require('foreach-batch')
然后,由于require函数不返回任何内容,因此您覆盖window.forEachBatch并变为未定义。
所以试试这个
require('foreach-batch')
forEachBatch(...);
我没有尝试过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.