安装电子模块时节点模块版本冲突 [英] node module version conflict when installing modules for electron

查看:198
本文介绍了安装电子模块时节点模块版本冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作电子应用程序( https://electron.atom.io/ )从我的串口读取数据。我是Web技术的新手,我知道一些javascript,但我是一个c ++人。

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, but I'm a c++ guy.

所以我从github快速入手,跑了

So I pulled in their quick-start from github, ran

npm install && npm start

随着这个轻松工作我尝试安装和运行serialport与

With this easily working I tried to install and run serialport with

npm install serialport

With我用一个测试文件安装并运行良好,我尝试将两者结合起来并在index.html文件中放入 require('serialport')。有了这个,我得到这个错误:

With that installed and running fine with a test file, I tried to combine the two and put require('serialport') in the index.html file. With this in there I get this error:

Uncaught Error: The module '/home/user/Documents/Programing/Git/Arduino-mpu6050/electron-quick-start/node_modules/serialport/build/Release/serialport.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 51. This version of Node.js requires
NODE_MODULE_VERSION 53. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at bindings (/home/user/Documents/Programing/Git/Arduino-mpu6050/electron-quick-start/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/home/user/Documents/Programing/Git/Arduino-mpu6050/electron-quick-start/node_modules/serialport/lib/bindings.js:3:35)

任何想法如何解决?我没有使用两个不同版本的Node,为什么我会收到此错误。

Any ideas how to fix it? I'm not using two different versions of Node, why am I getting this error.

系统操作系统信息:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial


推荐答案

当发生这种类型的版本不匹配时,您可以选择具有目标节点版本的电子分布,也可以重建npm包。由于Electron的发行版已跳过使用NODE_MODULE_VERSION 51配置的Node v7.0.0(并跳转到v7.4.0),因此您必须重建 serialport 包。

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.

在你的应用程序目录中(package.json所在的位置),

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

1。安装电子重建

1. Install electron-rebuild

npm install --save-dev electron -rebuild


2。重建

./ 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

看一下Electron的文档使用本机Node模块的页面。
https://electron.atom.io/docs / tutorial / using-native-node-modules /

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

这篇关于安装电子模块时节点模块版本冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆