Require在nodejs中不起作用:Uncaught ReferenceError:未定义require

时间:2019-06-11 14:27:21

标签: javascript node.js requirejs

我是Java的新手,并开始在nodejs和electronic的帮助下制作桌面应用程序。问题是我无法在main.js文件之外使用require()。但这在我在线上找到的一些教程中已显示。

如果可以找到解决方案,我搜索了几个小时,但是找不到。我试图重新安装nodejs,electron和requirejs模块。

  <div class="container">
    <form>
      <div>
        <label>Enter Item</label>
        <input type="text" id="item" autofocus>
      </div>
      <button class="waves-effect waves-light btn" type="submit">Add Item</button>
    </form>
  </div>

  <script>
    //should give back the item, so that it can be added to the shoppinglist in the main window
    const electron = require('electron');
    const {ipcRenderer} = electron;

    document.querySelector('form').addEventListener('submit', submitForm);

    function submitForm(e){
      e.preventDefault();
      const item = document.querySelector('#item').value;
      console.log(ipcRenderer);
      ipcRenderer.send('item:add', item);
    }
  </script>

预期:按“添加项目”按钮时,输入的项目应显示在mainWindow中

实际:按下按钮时什么也没发生(控制台说:“未捕获的ReferenceError:未定义require”)

0 个答案:

没有答案
相关问题