本篇目录
系统环境信息
安装先决条件
源码下载编译运行
遇到的问题
运行效果演示
1. 系统环境信息
Operating System: Windows 10 教育版 64-bit (10.0, Build 19041) (19041.vb_release.191206-1406)
Compiler: VS2019
2. 安装先决条件
1.安装nvm以指定安装特定版本的NodeJS,否则会出问题
nvm全名node.js version management,顾名思义是一个nodejs的版本管理工具。通过它可以安装和切换不同版本的nodejs。
直接到下面地址下载
https://github.com/coreybutler/nvm-windows/releases
1.点击接受
2.默认安装路径在 %appdata%\nvm 下
3.设置活跃版本路径
4.安装
5.安装中
6.安装完成
开始菜单中打开PowerShell
输入nvm 查看帮助信息
查看版本安装情况
这里选择安装 v11.11.0 版本
安装指定版本NodeJs 11.11.0,这里npm一起安装了
安装完后,文件夹内容如下:
设置当前使用的版本即nvm use 11.11.0
会创建C:\Program Files\nodejs 快捷方式 ,如下
相关安装路径如下:
https://nodejs.org/dist/v11.11.0/win-x64//node.exe - write C:\Users\Administrator\AppData\Roaming\nvm\v11.11.0\node64.exe
2.安装编译工具
安装前可以把PowerShell缓存设置大一点,以防出现问题把内容冲没了
npm install --global --production windows-build-tools
3. 源码下载编译运行
1.下载源码
git clone https://github.com/hechengjin/Mailspring.git
2.基于源码安装
cd mailspring
npm install
3.运行程序
npm start
4.生成用于打包的程序
查看package.json文件发现可以运行下面命令发布程序
npm run-script build
PS D:\github\he_chengjin_outlook\Mailspring> npm run-script build
> mailspring-root@0.0.1 build D:\github\he_chengjin_outlook\Mailspring
> grunt build-client --gruntfile=app/build/Gruntfile.js --base=./
Running "package" task
---> Running packager with options:
{ appVersion: '1.7.8',
platform: 'win32',
protocols:
[ { name: 'Mailspring Protocol',
schemes: [ 'mailspring', [length]: 1 ] },
{ name: 'Mailto Protocol', schemes: [ 'mailto', [length]: 1 ] },
[length]: 2 ],
dir: 'D:\\github\\he_chengjin_outlook\\Mailspring\\app',
appCategoryType: 'public.app-category.business',
tmpdir: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\nylas-build',
arch: 'ia32',
icon:
'D:\\github\\he_chengjin_outlook\\Mailspring\\app\\build\\resources\\win\\mailspring.ico',
name: 'Mailspring',
appCopyright:
'Copyright (C) 2014-2020 Foundry 376, LLC. All rights reserved.',
derefSymlinks: false,
asar:
{ unpack:
'{mailsync,mailsync.exe,mailsync.bin,*.so,*.so.*,*.dll,*.pdb,*.node,**/vendor/**,examples/**,**/src/tasks/**,**/static/all_licenses.html,**/node_modules/spellchecker/**,**/node_modules/windows-shortcuts/**}' },
ignore:
[ { /^\/build.*/ [lastIndex]: 0 },
{ /^\/dist.*/ [lastIndex]: 0 },
{ /^\/docs.*/ [lastIndex]: 0 },
{ /^\/docs_src.*/ [lastIndex]: 0 },
{ /^\/script.*/ [lastIndex]: 0 },
{ /^\/spec.*/ [lastIndex]: 0 },
{ /[\/]+gh-pages$/ [lastIndex]: 0 },
{ /[\/]+docs$/ [lastIndex]: 0 },
{ /[\/]+obj[\/]+gen/ [lastIndex]: 0 },
{ /[\/]+\.deps$/ [lastIndex]: 0 },
{ /\.md$/i [lastIndex]: 0 },
{ /\.log$/i [lastIndex]: 0 },
{ /\.yml$/i [lastIndex]: 0 },
{ /\.gz/i [lastIndex]: 0 },
{ /\.zip/i [lastIndex]: 0 },
{ /\.h$/ [lastIndex]: 0 },
{ /\.cc$/ [lastIndex]: 0 },
{ /\.flow$/ [lastIndex]: 0 },
{ /\.gyp/ [lastIndex]: 0 },
{ /\.mk/ [lastIndex]: 0 },
{ /\.dYSM$/ [lastIndex]: 0 },
{ /node_modules[\/]+less[\/]+dist$/ [lastIndex]: 0 },
{ /node_modules[\/]+react[\/]+dist$/ [lastIndex]: 0 },
{ /node_modules[\/].*[\/]tests?$/ [lastIndex]: 0 },
{ /node_modules[\/].*[\/]coverage$/ [lastIndex]: 0 },
{ /node_modules[\/].*[\/]benchmark$/ [lastIndex]: 0 },
{ /@paulbetts[\/]+cld[\/]+deps[\/]+cld/ [lastIndex]: 0 },
[length]: 27 ],
out: 'D:\\github\\he_chengjin_outlook\\Mailspring\\app\\dist',
overwrite: true,
prune: true,
osxNotarize: {},
win32metadata:
{ CompanyName: 'Foundry 376, LLC',
FileDescription: 'Mailspring',
LegalCopyright:
'Copyright (C) 2014-2020 Foundry 376, LLC. All rights reserved.',
ProductName: 'Mailspring' },
extendInfo:
'D:\\github\\he_chengjin_outlook\\Mailspring\\app\\build\\resources\\mac\\extra.plist',
appBundleId: 'com.mailspring.mailspring',
afterCopy:
[ { [Function: runCopyPlatformSpecificResources]
[length]: 5,
[name]: 'runCopyPlatformSpecificResources',
[arguments]: null,
[caller]: null,
[prototype]:
runCopyPlatformSpecificResources { [constructor]: [Circular] } },
{ [Function: runWriteCommitHashIntoPackage]
[length]: 5,
[name]: 'runWriteCommitHashIntoPackage',
[arguments]: null,
[caller]: null,
[prototype]: runWriteCommitHashIntoPackage { [constructor]: [Circular] } },
{ [Function: runCopySymlinkedPackages]
[length]: 5,
[name]: 'runCopySymlinkedPackages',
[arguments]: null,
[caller]: null,
[prototype]: runCopySymlinkedPackages { [constructor]: [Circular] } },
{ [Function: runTranspilers]
[length]: 5,
[name]: 'runTranspilers',
[arguments]: null,
[caller]: null,
[prototype]: runTranspilers { [constructor]: [Circular] } },
[length]: 4 ] }
---> Resolving symlinks
---> Packaging for 1s
---> Packaging for 2s
---> Packaging for 3s
.....
---> Packaging for 41s
Packaging app for platform win32 ia32 using electron v4.2.2
---> Packaging for 42s
.....
---> Packaging for 176s
---> Moving symlinked node modules / internal packages into build folder.
---> Running TypeScript Compiler
---> Compiling Users\ADMINI~1\AppData\Local\Temp\nylas-build\electron-packager\win32-ia32\Mailspring-win32-ia32\resources\app\internal_packages\account-sidebar\lib\account-commands.ts
---> Compiling Users\ADMINI~1\AppData\Local\Temp\nylas-build\electron-packager\win32-ia32\Mailspring-win32-ia32\resources\app\internal_packages\account-sidebar\lib\main.ts
.....
---> Compiling Users\ADMINI~1\AppData\Local\Temp\nylas-build\electron-packager\win32-ia32\Mailspring-win32-ia32\resources\app\src\sheet.tsx
---> Packaging for 194s
....
---> Packaging for 288s
---> Packaging for 289s
---> Done Successfully. Built into: D:\github\he_chengjin_outlook\Mailspring\app\dist\Mailspring-win32-ia32
Done, without errors.
打包完成后相关文件如下:
4. 遇到的问题
nodejs版本错误,如安装了12.18.3版本,则会报如下图错误
npm install安装时遇到以下问题
1.在如下路径下找不到MSBuild.exe文件
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\15.0\Bin\MSBuild.exe
-- Running npm install in ./app with electron config --> windows-quiet-hours@1.2.7 install D:\github\he_chengjin_outlook\Mailspring\app\node_modules\windows-quiet-hours> node-gyp rebuildD:\github\he_chengjin_outlook\Mailspring\app\node_modules\windows-quiet-hours>if not defined npm_config_node_gyp (node "D:\github\he_chengjin_outlook\Mailspring\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\Administrator\AppData\Roaming\nvm\v11.11.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )gyp ERR! UNCAUGHT EXCEPTIONgyp ERR! stack Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\15.0\Bin\MSBuild.exe ENOENTgyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:246:19)gyp ERR! stack at onErrorNT (internal/child_process.js:427:16)gyp ERR! stack at processTicksAndRejections (internal/process/next_tick.js:76:17)gyp ERR! System Windows_NT 10.0.19041gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\AppData\\Roaming\\nvm\\v11.11.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"gyp ERR! cwd D:\github\he_chengjin_outlook\Mailspring\app\node_modules\windows-quiet-hoursgyp ERR! node -v v11.11.0gyp ERR! node-gyp -v v3.8.0gyp ERR! This is a bug in `node-gyp`.gyp ERR! Try to update node-gyp and file an Issue if it does not help:gyp ERR! > runas@3.2.5 install D:\github\he_chengjin_outlook\Mailspring\app\node_modules\runas> prebuild-install || node-gyp rebuildprebuild-install WARN install No prebuilt binaries found (target=4.2.2 runtime=electron arch=x64 platform=win32)D:\github\he_chengjin_outlook\Mailspring\app\node_modules\runas>if not defined npm_config_node_gyp (node "D:\github\he_chengjin_outlook\Mailspring\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\Administrator\AppData\Roaming\nvm\v11.11.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )gyp ERR! UNCAUGHT EXCEPTIONgyp ERR! stack Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\15.0\Bin\MSBuild.exe ENOENTgyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:246:19)gyp ERR! stack at onErrorNT (internal/child_process.js:427:16)gyp ERR! stack at processTicksAndRejections (internal/process/next_tick.js:76:17)gyp ERR! System Windows_NT 10.0.19041gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\AppData\\Roaming\\nvm\\v11.11.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"gyp ERR! cwd D:\github\he_chengjin_outlook\Mailspring\app\node_modules\runasgyp ERR! node -v v11.11.0gyp ERR! node-gyp -v v3.8.0gyp ERR! This is a bug in `node-gyp`.gyp ERR! Try to update node-gyp and file an Issue if it does not help:gyp ERR! npm WARN optional SKIPPING OPTIONAL DEPENDENCY: windows-quiet-hours@1.2.7 (node_modules\windows-quiet-hours):npm WARN optional SKIPPING OPTIONAL DEPENDENCY: windows-quiet-hours@1.2.7 install: `node-gyp rebuild`npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 7npm ERR! code ELIFECYCLEnpm ERR! errno 7npm ERR! runas@3.2.5 install: `prebuild-install || node-gyp rebuild`npm ERR! Exit status 7npm ERR!npm ERR! Failed at the runas@3.2.5 install script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-08-01T10_19_09_457Z-debug.lognpm ERR! code ELIFECYCLEnpm ERR! errno 7npm ERR! mailspring-root@0.0.1 postinstall: `node scripts/postinstall.js`npm ERR! Exit status 7npm ERR!npm ERR! Failed at the mailspring-root@0.0.1 postinstall script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-08-01T10_19_09_534Z-debug.log
修改
C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js
文件
把
variables['msbuild_path'] = path.join(vsSetup.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
中的 '15.0' 改成 'Current'
2.PowerShell中的中文显示乱码
查看当前字符编码
chcp
936
修改为中文编码
chcp 65001
或者尝试使用 powershell_ise.exe
3.better-sqlite3编译错误
无法找到 Visual Studio 2015 的生成工具(平台工具集 =“v140”)。若要使用 v140 生成工具进行生成,请安装 Visual Studio 2015 生成工具。
正常情况下如果有下面错误日志中的这个工程,把相关平台改成v142即vs2019就好,但发现报错后
\Mailspring\app\node_modules\better-sqlite3\build\deps\action_before_build.vcxproj
这个文件路径已经不存在了。
详细报错日志如下:
> better-sqlite3@1.3.6 install D:\github\he_chengjin_outlook\Mailspring\app\node_modules\better-sqlite3> node installD:\github\he_chengjin_outlook\Mailspring\app\node_modules\better-sqlite3>if not defined npm_config_node_gyp (node "D:\github\he_chengjin_outlook\Mailspring\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\Administrator\AppData\Roaming\nvm\v11.11.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )在此解决方案中一次生成一个项目。若要启用并行生成,请添加“-m”开关。C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(390,5): error MSB8020: 无法找到 Visual Studio 2015 的生成工具(平台工具集 =“v140”)。若要使用 v140 生成工具进行生成,请安装 Visual Studio 2015 生成工具。或者,可以升级到当前 Visual Studio 工具,方式是通过选择“项目”菜单或右键单击该解决方案,然后选择“重定解决方案目 标”。[D:\github\he_chengjin_outlook\Mailspring\app\node_modules\better-sqlite3\build\deps\action_before_build.vcxproj]gyp ERR! build errorgyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1gyp ERR! stack at ChildProcess.onExit (C:\Users\Administrator\AppData\Roaming\nvm\v11.11.0\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)gyp ERR! stack at ChildProcess.emit (events.js:197:13)gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)gyp ERR! System Windows_NT 10.0.19041gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\AppData\\Roaming\\nvm\\v11.11.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"gyp ERR! cwd D:\github\he_chengjin_outlook\Mailspring\app\node_modules\better-sqlite3gyp ERR! node -v v11.11.0gyp ERR! node-gyp -v v3.8.0gyp ERR! not oknpm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! better-sqlite3@1.3.6 install: `node install`npm ERR! Exit status 1npm ERR!npm ERR! Failed at the better-sqlite3@1.3.6 install script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-08-01T11_51_47_240Z-debug.lognpm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! mailspring-root@0.0.1 postinstall: `node scripts/postinstall.js`npm ERR! Exit status 1npm ERR!npm ERR! Failed at the mailspring-root@0.0.1 postinstall script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-08-01T11_51_47_353Z-debug.log
安装一下Visual Studio 2015 生成工具
进入
https://visualstudio.microsoft.com/zh-hans/vs/older-downloads/
页面
"可再发行组件和生成工具" -> "查找 Microsoft 生成工具 2015 更新 3"
然后点下载
下载后执行 visualcppbuildtools_full.exe安装程序
安装过程如下:
选自定义安装相关组件
这里安装windows 10 sdk
点 安装
安装进行中
安装完成后,上面问题即可解决
4. Error: EPERM: operation not permitted, rename
npm start 时,第一次运行会报
index.js:26 Error: EPERM: operation not permitted, rename 'C:\Users\Administrator\AppData\Roaming\Mailspring-dev\compile-cache\ts\9e22ff4f512270e80b49c297abbfe170716f76d4\ae722f5fe33cc915ea57754494cce0a82cca4cd2.js.14724' -> 'C:\Users\Administrator\AppData\Roaming\Mailspring-dev\compile-cache\ts\9e22ff4f512270e80b49c297abbfe170716f76d4\ae722f5fe33cc915ea57754494cce0a82cca4cd2.js' at Object.renameSync (fs.js:591) at writeCachedJavascript (D:\github\he_chengji…compile-cache.js:32) at compileFileAtPath (D:\github\he_chengji…compile-cache.js:53) at Object.value [as .ts] (D:\github\he_chengji…ompile-cache.js:144) at Module.load (internal/modules/cjs/loader.js:602) at tryModuleLoad (internal/modules/cjs/loader.js:541) at Function.Module._load (internal/modules/cjs/loader.js:533) at Module.require (internal/modules/cjs/loader.js:640) at require (internal/modules/cjs/helpers.js:20) at setupWindow (index.js:47)
但第二次再重启执行就没问题了
4.better_sqlite3.node is not a valid Win32 application
打包生成的程序报上面的错误
You should use Windows x86 OS for building your project because the better-sqlite3 has native dependencies. I use this way for my electron app.
这个没再深究,直接下载一个对应平台的官方版本,把对应的文件复制过去即可。
5.keytar.node is not a valid Win32 application.
\resources\app.asar.unpacked\node_modules\keytar\build\Release\keytar.node is not a valid Win32 application.
一样的处理方法
6.mailsync下载不下来的会提示如下错误
Mailspring可以找到mailsync进程。如果您要从源代码构建Mailspring,请确保已在工作副本中下载并解压缩mailsync.tar.gz
可以直接从下面地址下载mailsync.tar.gz,
链接:https://pan.baidu.com/s/1t0gmb0-scHf4cUkVCFoBkA
提取码:ibs2
下载后解压到./app目录下即可