Using Node.js addons in Electron's renderer with Webpack

后端 未结 4 1335
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-10 20:23

I have the following renderer:

import SerialPort from \"serialport\";

new SerialPort(\"/dev/tty-usbserial1\", { baudRate: 57600 });

It\'s buil

4条回答
  •  伪装坚强ぢ
    2021-02-10 21:08

    I had a similar error when tried to use a native module in electron-renderer.
    Although the error message was something like this in my case:

    node-loader: The specified module could not be found

    I believe it's all related to node loaders. For me, native-addon-loader was the loader that worked great.
    Also, make sure your Webpack target is either node, electron-main or electron-renderer, otherwise it won't work (native modules can't be used on the client side).

提交回复
热议问题