当前位置: 首页 > 面试题库 >

安装电子模块时,节点模块版本冲突

申屠晟
2023-03-14
问题内容

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

所以我从github上拉了他们的快速入门,

npm install && npm start

有了这个容易的工作,我试图用

npm install serialport

安装了该文件并通过测试文件正常运行后,我尝试将两者结合起来并放入require('serialport')index.html文件中。有了这个我得到这个错误:

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,为什么会出现此错误。

系统操作系统信息:

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

问题答案:

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

在您应用的目录(package.json所在的目录)中,

1.安装electron-rebuild

npm install --save-dev electron-rebuild

2.重建

./node_modules/.bin/electron-rebuild

或者,甚至是更好的选择 -首先设置环境变量。

# 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的文档页面。 https://electron.atom.io/docs/tutorial/using-
native-node-modules/



 类似资料:
  • (网页包)/buildin/global。js有多个模块,它们的名称只是大小写不同。在具有其他case语义的文件系统上编译时,这可能会导致意外行为。使用相等的外壳。比较这些模块标识符: C:\Users\user\Desktop\projects\LINK\LinkparmacySystem\node\u modules\react scripts\node\u modules\babel loa

  • 我正在尝试安装节点帮助模块,但经过多次尝试,我不断得到以下错误。node-help包的安装是否已中断? /usr/local/lib/node_modules/node-help/bin/node-help:6 const{homedir}=require('os');^ SyntaxError:意外标记{at exports.runinthiscontext(VM.js:53:16)at mod

  • 我有一个问题时运行命令"npm安装"。我想安装大口和鲍尔模块,但当我运行"npm安装"或"npm安装鲍尔"我得到了一个错误VS2013.我为什么会有这个错误?如何解决这个问题?以下是我安装的指定版本: 节点v10.15 npm v6.10.3 python v2.7 VSCODE v1.37.1(用户设置) 我已经添加代理配置: npm配置设置https代理超文本传输协议://xxxxx npm配

  • 我的maven构建很好,能够从CLI运行groovy。但是,如果我试图在IntelliJ Idea(version15 community edition)中运行我的groovy类,它会给我以下错误。 这是我在系统中安装的groovy版本。 如果有人知道这件事,请告诉我。

  • 我正在尝试从github安装Exscript。 当我试图加载它时,python找不到它: 但是,当我尝试用setup在同一个虚拟环境中安装它时。py它成功安装并加载。 我做错了什么?

  • 问题内容: 问题答案: 您是否使用-g选项安装了模块?我认为并不是每个模块都打算在全球范围内安装,而是尝试为要创建的项目在本地安装(npm install),然后检查错误是否仍然存在。