Electron Client Build Failed in Windows

I use windows 10 as a main OS.

Today, due to some issues I had to delete and reclone the repo. So I just cloned the source code from GitHub, Then I ran npm install command and got error. Here is my terminal log:

R:\Dev\joplin-kowalskidev>npm install

> husky@3.0.2 install R:\Dev\joplin-kowalskidev\node_modules\husky
> node husky install

husky > Setting up git hooks
husky > Done

> husky@3.0.2 postinstall R:\Dev\joplin-kowalskidev\node_modules\husky
> opencollective-postinstall || true

Thank you for using husky!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/husky/donate


> joplin@1.0.0 postinstall R:\Dev\joplin-kowalskidev
> cd Tools && npm i && cd .. && cd ReactNativeClient && npm i && cd .. && cd ElectronClient && npm i && cd .. && cd CliClient && npm i && cd 
.. && gulp build

added 138 packages from 151 contributors and audited 174 packages in 22.122s
found 0 vulnerabilities


> core-js@2.6.11 postinstall R:\Dev\joplin-kowalskidev\ReactNativeClient\node_modules\fbjs-scripts\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.11 postinstall R:\Dev\joplin-kowalskidev\ReactNativeClient\node_modules\metro-babel-register\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> core-js@2.6.11 postinstall R:\Dev\joplin-kowalskidev\ReactNativeClient\node_modules\metro\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> core-js@2.6.11 postinstall R:\Dev\joplin-kowalskidev\ReactNativeClient\node_modules\react-native\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> Joplin@0.8.0 postinstall R:\Dev\joplin-kowalskidev\ReactNativeClient
> patch-package --patch-dir ../patches && jetify && npm run build

patch-package 6.2.1
Applying patches...
htmlparser2@4.1.0 ✔
sax@1.2.4 ✔
Jetifier found 1235 file(s) to forward-jetify. Using 8 workers...

> Joplin@0.8.0 build R:\Dev\joplin-kowalskidev\ReactNativeClient
> gulp build

[17:58:31] Using gulpfile R:\Dev\joplin-kowalskidev\ReactNativeClient\gulpfile.js
[17:58:31] Starting 'build'...
[17:58:31] Starting 'buildReactNativeInjectedJs'...
[17:58:31] Finished 'buildReactNativeInjectedJs' after 13 ms
[17:58:31] Starting 'encodeAssets'...
[17:58:32] Finished 'encodeAssets' after 532 ms
[17:58:32] Starting 'podInstall'...
[17:58:32] Finished 'podInstall' after 1.47 ms
[17:58:32] Finished 'build' after 553 ms
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1250 packages from 913 contributors and audited 75105 packages in 204.543s

4 packages are looking for funding
  run `npm fund` for details

found 96 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

> sqlite3@4.1.1 install R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
[sqlite3] Success: "R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\sqlite3\lib\binding\node-v72-win32-x64\node_sqlite3.node" is installed via remote

> ejs@3.0.1 postinstall R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)


> core-js@3.6.4 postinstall R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\global-agent\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> electron@7.1.14 postinstall R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\electron
> node install.js


> Joplin@1.0.197 postinstall R:\Dev\joplin-kowalskidev\ElectronClient
> npm run build && gulp electronRebuild


> Joplin@1.0.197 build R:\Dev\joplin-kowalskidev\ElectronClient
> patch-package --patch-dir ../patches && gulp build

patch-package 6.2.0
Applying patches...
htmlparser2@4.1.0 ✔
sax@1.2.4 ✔
[18:01:40] Using gulpfile R:\Dev\joplin-kowalskidev\ElectronClient\gulpfile.js
[18:01:40] Starting 'build'...
[18:01:40] Starting 'compileScripts'...
[18:01:40] Starting 'compilePackageInfo'...
[18:01:40] Starting 'copyPluginAssets'...
[18:01:40] Starting 'copyLib'...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ClipperConfigScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ConfigMenuBar.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ConfigScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/DialogButtonRow.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/DropboxLoginScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/EncryptionConfigScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ExtensionBadge.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/Header.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/HelpButton.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/IconButton.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ImportScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ItemList.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/MainScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/Navigator.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NoteList.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NotePropertiesDialog.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NoteRevisionViewer.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NoteSearchBar.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NoteStatusBar.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NoteText.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/NoteTextViewer.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/OneDriveLoginScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/PromptDialog.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/Root.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/SideBar.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/StatusScreen.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/TagItem.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/TagList.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/Toolbar.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ToolbarButton.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/ToolbarSpace.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/VerticalResizer.jsx...
Compiling R:\Dev\joplin-kowalskidev\ElectronClient\tools/../plugins/GotoAnything.jsx...
Copying to R:\Dev\joplin-kowalskidev\ElectronClient\tools/../gui/note-viewer/pluginAssets
[18:02:27] Finished 'compileScripts' after 48 s
[18:02:28] Finished 'compilePackageInfo' after 48 s
Copying to R:\Dev\joplin-kowalskidev\ElectronClient\tools/../pluginAssets
[18:02:28] Finished 'copyPluginAssets' after 48 s
[18:02:29] Finished 'copyLib' after 49 s
[18:02:29] Starting 'tsc'...
[18:02:41] Finished 'tsc' after 12 s
[18:02:41] Finished 'build' after 1.02 min
[18:02:44] Using gulpfile R:\Dev\joplin-kowalskidev\ElectronClient\gulpfile.js
[18:02:44] Starting 'electronRebuild'...
Running: "R:\Dev\joplin-kowalskidev\ElectronClient\tools/../node_modules/.bin/electron-rebuild.cmd" --arch ia32
[18:03:13] 'electronRebuild' errored after 29 s
[18:03:13] Error: Command failed: "R:\Dev\joplin-kowalskidev\ElectronClient\tools/../node_modules/.bin/electron-rebuild.cmd" --arch ia32     
- Searching dependency tree
× Rebuild Failed

An unhandled error occurred inside electron-rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
  unpack_sqlite_dep
  'C:\Users\Zaid' is not recognized as an internal or external command,
  operable program or batch file.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(231,5): error MSB6006: "cmd.exe" exited with code 1. [R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\sqlite3\build\deps\action_before_build.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 
1
gyp ERR! stack     at ChildProcess.onExit (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "R:\\Dev\\joplin-kowalskidev\\ElectronClient\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=7.1.14" "--arch=ia32" "--dist-url=https://electronjs.org/headers" "--build-from-source" "--module_name=node_sqlite3" "--module_path=R:\\Dev\\joplin-kowalskidev\\ElectronClient\\node_modules\\sqlite3\\lib\\binding\\electron-v7.1-win32-ia32" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.1.1/{toolset}/" "--package_name=electron-v7.1-win32-ia32.tar.gz"
gyp ERR! cwd R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\sqlite3
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v6.0.1
gyp ERR! not ok

Failed with exit code: 1

Error: Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
  unpack_sqlite_dep
  'C:\Users\Zaid' is not recognized as an internal or external command,
  operable program or batch file.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(231,5): error MSB6006: "cmd.exe" exited with code 1. [R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\sqlite3\build\deps\action_before_build.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 
1
gyp ERR! stack     at ChildProcess.onExit (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "R:\\Dev\\joplin-kowalskidev\\ElectronClient\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=7.1.14" "--arch=ia32" "--dist-url=https://electronjs.org/headers" "--build-from-source" "--module_name=node_sqlite3" "--module_path=R:\\Dev\\joplin-kowalskidev\\ElectronClient\\node_modules\\sqlite3\\lib\\binding\\electron-v7.1-win32-ia32" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.1.1/{toolset}/" "--package_name=electron-v7.1-win32-ia32.tar.gz"
gyp ERR! cwd R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\sqlite3
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v6.0.1
gyp ERR! not ok

Failed with exit code: 1
    at SafeSubscriber._error (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\spawn-rx\lib\src\index.js:267:84)
    at SafeSubscriber.__tryOrUnsub (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:205:16)
    at SafeSubscriber.error (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:156:26)
    at Subscriber._error (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:92:26)
    at Subscriber.error (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:72:18)
    at MapSubscriber.Subscriber._error (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:92:26)
    at MapSubscriber.Subscriber.error (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:72:18)
    at SafeSubscriber._next (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\spawn-rx\lib\src\index.js:242:65)
    at SafeSubscriber.__tryOrUnsub (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:205:16)
    at SafeSubscriber.next (R:\Dev\joplin-kowalskidev\ElectronClient\node_modules\rxjs\internal\Subscriber.js:143:22)

    at ChildProcess.exithandler (child_process.js:303:12)
    at ChildProcess.emit (events.js:311:20)
    at ChildProcess.EventEmitter.emit (domain.js:505:15)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Joplin@1.0.197 postinstall: `npm run build && gulp electronRebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Joplin@1.0.197 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\Zaid Kesarani\AppData\Roaming\npm-cache\_logs\2020-04-03T12_33_13_989Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! joplin@1.0.0 postinstall: `cd Tools && npm i && cd .. && cd ReactNativeClient && npm i && cd .. && cd ElectronClient && npm i && cd 
.. && cd CliClient && npm i && cd .. && gulp build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the joplin@1.0.0 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\Zaid Kesarani\AppData\Roaming\npm-cache\_logs\2020-04-03T12_33_14_176Z-debug.log

R:\Dev\joplin-kowalskidev>npm start
npm ERR! missing script: start

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Zaid Kesarani\AppData\Roaming\npm-cache\_logs\2020-04-03T12_35_25_925Z-debug.log

I know this issue very well. This is related to SQlite dependency and we need to rebuild this again after installing SQLite. So for that we have electronRebuild.js in ElectronClient > tools
to fix this issue but in this file there is a bug here:

console.info(await execCommand([`"${exePath}"`, `--arch ia32`].join(' ')));

To run electron-rebuild.cmd we need to pass one command line arguments i.e module directory which is the path to package.json we have to pass argument like this --module-dir <path-to-package.json> .

So here is my fix:
Replacing the --arch ia32 with --module-dir ${__dirname}/.. fix the issue! So the new code would be:

console.info(await execCommand([`"${exePath}"`, `--module-dir ${__dirname}/..`].join(' ')));

@laurent Can I open new GH issue regarding the same ?

You need to add quotes somewhere because you username has a space in it. In general it’s best no to have spaces in paths when doing development work, as it’s likely you’ll hit edge cases like this now and then.

But why does it work for everybody and in continuous integration, but not for you? I guess it would be best to fix whatever issue is specific to your computer. That particular command is used in CI and I'd rather not change it since it works.

Yaa I know that's the biggest mistake I've ever did since I bought new laptop :expressionless: I used space in my username while configuring my new laptop. Facing a lot of trouble in development.

Okay…We should keep it as it is.

I believe it can be changed from the Control Panel, but then I have not used Windows for development in three years.

Yes you are right! We can change from setting but that mess up with Windows Registry. I have tried changing name I followed some tutorials but that doesn't work in my system and unfortunately my account was crashed and it took whole day to fix and get back my account so after that incident I decided not to mess with Windows Registry :sweat_smile:

Well maybe you can consider switching to Linux…

Yea…I have already dual boot system Windows & Ubuntu. It’s just taking time to get familiar with Linux…

O ok, it will happen over time. Dont’t worry.

1 Like

I feel that this is very unfriendly to windows. Do you use Linux for development every day?
It seems that development under Windows must install Visual Studio. I don’t want to install the Big Mac. If Linux support is better, maybe, I can try Win/Linux dual system

This project is actually friendlier than the average for Windows development because I use Windows. Normally you don’t need to install Visual Studio, just the windows build tools as described in the doc.

Thanks, i will try

Linux has always been developer-centric and off late has also become consumer-friendly as well (with Linux Mint, Pop OS and Manjaro…). It will never be as simple a setup in Windows as it is in Linux, like sudo apt install ... or sudo pacman -S ... So, as far as development is the question, Linux works better. On the other hand, as @laurent mentions, it is not necessary to switch to Linux just to develop Joplin, because its setup is relatively painless compared to other things in Windows (and please don’t use WSL for dev, it just screws stuff more than anything; it is only good for testing and even then it is better to use Virtual Box or VMWare directly).
So in conclusion. use Linux if you like it, but it is not a necessity to develop for Joplin.