Electron项目在mac系统运行问题记录

641 阅读2分钟

gyp ERR! build error gyp ERR!

报错信息:

gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2

尝试以下解决方法:

  1. 尝试降低node版本
  2. sudo npm install --unsafe-perm或 ``````sudo yarn --unsafe-perm```
npm install --global --production windows-build-tools
npm install -g node-gyp

仍然报错...

gyp info it worked if it ends with ok
gyp info using node-gyp@9.3.1
gyp info using node@10.14.1 | darwin | x64
gyp info find Python using Python version 3.8.9 found at "/Library/Developer/CommandLineTools/usr/bin/python3"
gyp ERR! UNCAUGHT EXCEPTION 
gyp ERR! stack TypeError: Object.fromEntries is not a function
......

发现虽然用nvm切换了node版本为10.14.1,安装了python2.7和node-gyp@4.0.0, 但之前在别的版本安装了node-gyp@9.3.1,还是会运行node-gyp@9.3.1和Python 3.8.9的环境

于是切换环境全局卸载node-gyp,再重装

nvm use v14.18.1
npm uninstall -g node-gyp
nvm use v10.14.1
npm i -g node-gyp@4.0.0

查看python路径,

git:(v2.0.15) ✗ python
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 19 2020, 20:48:48) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages']
>>> 

指定到2.7版本

node-gyp --python /Library/Frameworks/Python.framework/Versions/2.7/
npm config set python /Library/Frameworks/Python.framework/Versions/2.7/

切换成功

参考资料

Installation notes for macOS Catalina (v10.15)

查看Mac本机的Python3的安装路径

node-gyp环境配置报错处理,nodejs 调用 c++接口

The module XX was compiled against a different Node.js version

报错信息:

App threw an error during load
ase/node_printer.node' Error: The module '..../node_modules/node-printer-escpos/node_modules/printer/build/Rele 
was compiled against a different Node.js version using NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 69. 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:160:31) at Object.Module._extensions..node(internal/modules/cjs/loader.js:722:18) at Object.module.(anonymous function) [as .node](ELECTRON_ASAR.js:160:31) at Module.load (internal/modules/cjs/loader.js:602:32) at tryModuleLoad(internal/modules/cjs/loader.js:541:12)
at Function.Module._load (internal/modules/cjs/loader.js:533:3) at Module.require(internal/modules/cjs/loader.js:640:17) at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous>(/Users/yuki01.ye/Documents/Workspace/gitlab/xpos/vpos-fe/node_modules/node-printer-escpos/node_modules/printer/li
b/printer.js:10:22)

参考资料

# electron程序,如何理解NODE_MODULE_VERSION?

nodejs.org/en/download…

# electron-vue引入squlite3模块,并解决Uncaught Error:cannot find module的问题

解决思路

重新构建Electron,使两者NODE_MODULE_VERSION版本统一

尝试解决方案

npm install --save-dev electron-rebuild

MAC:./node_modules/.bin/electron-rebuild

Windowns:.\node_modules\.bin\electron-rebuild.cmd

Dynamic Linking Error: dlopen(xx.dll.dylib, 0x0002): (no such file)

报错信息:

Error: Dynamic Linking Error: dlopen(..../dll/posinf.dll.dylib, 0x0002): tried: '..../dll/posinf.dll.dylib' (no such file)

报错原因:

.ddl文件是windows平台的动态链接库,mac平台的是.dylib,而代码里面只有.dll文件,mac系统无法打开

image.png