node module in Electron

我的未来我决定 提交于 2020-01-16 18:18:14

问题


Need help on getting babyparse module working in Electron, after npm install babyparse module and still getting Uncaught Error: Cannot find module 'babyparse'.

var Baby = require("babyparse");
window.$ = window.jQuery = require('./jquery.min.js');
var csv;
function readyFn(d){

parsed = Baby.parse(csv);

Papa.parse(data, {
    complete: function(results) {
        console.log("Finished:", results.data);
    }
});
}
$(document).ready(readyFn);

回答1:


I had to re-bind require to window before using it.

In your index.html file (loaded my Electron), before loading your js, add window.nRequire = require. Then call var Baby = nRequire("babyparse"); anywhere in your app.




回答2:


You could try following:

  1. check if the module is inside your node_modules folder of your electron app.
  2. If it is not install it via npm install babyparse --save be sure that you have the "--save" at the end, to install it inside your app and not global.
  3. If it is allready inside your node_modules folder, maybe something went wrong, when you installed it. So uninstall it npm uninstall babyparse --save and install it again. Or better you could also run a complete npm install inside your electron folder for updating all your modules.



回答3:


  • Remove your node_modules folder
  • npm cache clean
  • npm install


来源:https://stackoverflow.com/questions/33856012/node-module-in-electron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!