node module version conflict when installing modules for electron

前端 未结 3 1578
被撕碎了的回忆
被撕碎了的回忆 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:37

    When this type of version mismatch occurs, you can either choose an electron distribution with the target Node version or rebuild the npm package. Since Electron's distribution has skipped Node v7.0.0 which is configured with NODE_MODULE_VERSION 51 (and jumped to v7.4.0), you would have to rebuild the serialport package.

    In your app's directory (where package.json is located at),

    1. Install electron-rebuild

    npm install --save-dev electron-rebuild


    2. Rebuild

    ./node_modules/.bin/electron-rebuild



    Or, even a better option - set environment variables from the first place.

    # Electron's version.
    export npm_config_target=1.6.1
    # The architecture of Electron, can be ia32 or x64.
    export npm_config_arch=x64
    export npm_config_target_arch=x64
    # Download headers for Electron.
    export npm_config_disturl=https://atom.io/download/electron
    # Tell node-pre-gyp that we are building for Electron.
    export npm_config_runtime=electron
    # Tell node-pre-gyp to build module from source code.
    export npm_config_build_from_source=true
    # Install all dependencies, and store cache to ~/.electron-gyp.
    HOME=~/.electron-gyp npm install
    

    Take a look at the Electron's documentation page for using native Node modules. https://electron.atom.io/docs/tutorial/using-native-node-modules/

提交回复
热议问题