node module version conflict when installing modules for electron

前端 未结 3 1574
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 07:17

I\'m trying to make an Electron application (https://electron.atom.io/) that reads data from my serial port. I\'m new to web technologies in general, I know some javascript,

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 07:41

    electron-rebuild on postinstall.

    Depending on what you're doing, you can use electron-rebuild to rebuild serialport to the version of electron you have installed.

    To do so:

    npm install --save-dev electron-rebuild
    
    $(npm bin)/electron-rebuild                 # Mac and Linux.
    
    .\node_modules\.bin\electron-rebuild.cmd    # Windows.
    

    Because I kept forgetting to do this after doing an npm install (and to help others that downloaded the project), I added the following two scripts to package.json:

    "scripts": {
      "start": "electron .",
    
      "postinstall": "electron-rebuild",    
      "electron-rebuild": "electron-rebuild"
    },
    

    The postinstall will automatically run after doing a npm install so after the typical install finishes you'll see a console log message with electron-rebuild and it will automatically rebuild serialport, and any other native library you have, to the electron version. This means that you shouldn't even have to think about running electron-rebuild going forward.

提交回复
热议问题