.\node_modules\.bin\electron-rebuild.cmd
环境:
系统:win10
"dependencies": {
"core-js": "^3.6.5",
"electron-rebuild": "^3.2.3",
"escpos-serialport": "^3.0.0-alpha.4",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"electron": "^13.0.0",
"electron-devtools-installer": "^3.1.0",
"electron-prebuilt": "^1.4.13",
"electron-rebuild": "^3.2.3",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"serialport": "^9.2.1",
"vue-cli-plugin-electron-builder": "~2.1.1",
"vue-template-compiler": "^2.6.11"
},
小知识:你安装electron-rebuild之后要把它运动到dependencies中
执行之后报错如下:
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\gyp_main.py", line 45, in <module>
sys.exit(gyp.script_main())
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\__init__.py", line 662, in script_main
return main(sys.argv[1:])
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\__init__.py", line 654, in main
return gyp_main(args)
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\__init__.py", line 629, in gyp_main
options.circular_check,
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\__init__.py", line 151, in Load
params["root_targets"],
⠼ Building module: bindings, Completed: 0 File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 3010, in Load
build_file, data, aux_data, variables, includes, depth, check, True
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 428, in LoadTargetBuildFile
build_file_data, PHASE_EARLY, variables, build_file_path
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 1411, in ProcessVariablesAndConditionsInDict
ProcessVariablesAndConditionsInList(value, phase, variables, build_file)
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 1424, in ProcessVariablesAndConditionsInList
ProcessVariablesAndConditionsInDict(item, phase, variables, build_file)
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 1411, in ProcessVariablesAndConditionsInDict
ProcessVariablesAndConditionsInList(value, phase, variables, build_file)
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 1428, in ProcessVariablesAndConditionsInList
expanded = ExpandVariables(item, phase, variables, build_file)
File "F:\my\code\electron\my-electron\node_modules\_node-gyp@8.2.0@node-gyp\gyp\pylib\gyp\input.py", line 979, in ExpandVariables
p_stdout = p_stdout.decode("utf-8")
AttributeError: 'str' object has no attribute 'decode' while trying to load binding.gyp
✖ Rebuild Failed
An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'F:\my\code\electron\my-electron\node_modules\_@serialport_bindings@9.2.1@@serialport\bindings'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
Error: `gyp` failed with exit code: 1
Error: node-gyp failed to rebuild 'F:\my\code\electron\my-electron\node_modules\_@serialport_bindings@9.2.1@@serialport\bindings'.
就很 "shabi",我系统的python版本就是2.7.3的(也切换3.7尝试也不行),可是还是报这个错误。
最后解决方案就是修改源码(同时也把python版本指向2.7)
1.编辑器打开这个源码文件
2.修改源码
然后再次运行
.\node_modules\.bin\electron-rebuild.cmd
就搞定了,真 "shabi"。
补充,下面查看npm执行的时候使用的配置
npm config get userconfig
把这里的python设置成python,就会根据你配置的环境变量来使用python版本