mac上怎么运行node.js文件_Windows 10下编译运行 Mailspring

本篇目录

  1. 系统环境信息

  2. 安装先决条件

  3. 源码下载编译运行

  4. 遇到的问题

  5. 运行效果演示

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

f108800d8edadf48d5bd6cd2a915e1fa.png

1.点击接受

0ed9276e8c871f28b9984f7ef18e7756.png

2.默认安装路径在 %appdata%\nvm 下

3661c10020d087bd7241d8cbee12ef64.png

3.设置活跃版本路径

c15144925526779a81316e15e2cdf565.png

4.安装

bac4f33cf09d955908331f0056d6d78c.png

5.安装中

ef8eb828e6ff720aa83e28e70dff80f2.png

6.安装完成

fafbb67b21b10116f8cda7dabd50c8a5.png

开始菜单中打开PowerShell

67dab53b076d413434de923b69bb9b68.png

输入nvm 查看帮助信息

ff8f5e589b861237c48c56fa48ed69f6.png

查看版本安装情况

bb2f39d4baba18003ce54f8c329c86f6.png

这里选择安装 v11.11.0 版本

9b96723c27b61d5c16fc73958b9bc7bd.png

安装指定版本NodeJs 11.11.0,这里npm一起安装了

55d772137e7636c7a4da44d7dd44910b.png

安装完后,文件夹内容如下:

f7317536ee6bc605ecca91aad49a5396.png

设置当前使用的版本即nvm use 11.11.0

d2854f9b1860d7c8c0dbbedbc97b3b56.png

会创建C:\Program Files\nodejs 快捷方式 ,如下

998f3432c79a0ca4cea68bf1f8eec436.png

相关安装路径如下:

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缓存设置大一点,以防出现问题把内容冲没了

0a1df2d43391d9e521c6529ccc0258f6.png

npm install --global --production windows-build-tools

6bcf8cf1bd004c39ecc9874bf8c0bdd8.png

3. 源码下载编译运行

1.下载源码

git clone https://github.com/hechengjin/Mailspring.git

bdeae97d531bc968d4e92c93a33f15f4.png

2.基于源码安装

cd mailspringnpm install

dd0ca08df41f65375c369042f3c5078c.png

3.运行程序

npm start

8f255030baa182d8f89aa175b6147cca.png

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 41sPackaging 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-ia32Done, without errors.

打包完成后相关文件如下:

e3c49ebb846954fa90bf16b898c4fc3d.png

4. 遇到的问题

nodejs版本错误,如安装了12.18.3版本,则会报如下图错误

eba32e7b5a1b411dad9ed6b03173fa70.png

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中的中文显示乱码

2a0fffca99e0a9b73dcdfdd6adb4506e.png

查看当前字符编码

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" 

然后点下载

2018c70b277cc2292aafacfa1a2ed755.png

下载后执行 visualcppbuildtools_full.exe安装程序

安装过程如下:

60e454fd5b4ddb16cac628890d69736a.png

选自定义安装相关组件

5a572116ddd228f09dd97fff87ecbd3c.png

这里安装windows 10 sdk

faf4314d244d72c7b3679cc37fbd2912.png

点 安装

ae07cd40a6204aef2f83b16e67992def.png

安装进行中

4395bf23cbd1abb9a09a6dbfb9fdbfad.png

安装完成后,上面问题即可解决

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)

60c73d8a029e93c86e4cfd62db8b7076.png

但第二次再重启执行就没问题了

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.

这个没再深究,直接下载一个对应平台的官方版本,把对应的文件复制过去即可。

0dd3a7583c31ce5db3efeff46f089c8d.png

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.

一样的处理方法

19cb48ab5b8437c3219e6a164f67ff73.png

6.mailsync下载不下来的会提示如下错误

Mailspring可以找到mailsync进程。如果您要从源代码构建Mailspring,请确保已在工作副本中下载并解压缩mailsync.tar.gz

e83fbfbe3197f52eab74b3e4e7b23dfe.png

可以直接从下面地址下载mailsync.tar.gz,

链接:https://pan.baidu.com/s/1t0gmb0-scHf4cUkVCFoBkA 

提取码:ibs2

下载后解压到./app目录下即可

7ef5c5da76e4823d557c8973804b3725.png

5. 运行效果演示

2391cf27cb01f50661e2df8b35289043.png

59f6ee56f43d5b1a26140706b78cae8b.png

a356878b38cd9ba08b52b8b05166125c.png

3bc240eedd83f3244782becd2396a0d5.png

48f744a44d583424baf6bd59bc77df97.png

8dfa0a02d3ce51c32aaa990349613184.png

06906cfa76a2552c6db4efa4895dcb45.png

6b27ce6cbd5f7d01cbac42d4750f68bb.png

792bd75de5e75cf9eb0cf7916b8dad7c.png

046a3f40f5bf885d62753db6792818af.png

4888307651929d7e34ee788a71f390db.png

5460e661ad04e51fa61d35e3ca275808.png

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值