Cannot run packages/app-desktop due an issue with node_sqlite3.node

I am attempting to build the desktop app with a view to submitting a pull request.

I am following the BUILD.md guide.

When I run cd packages/app-desktop then yarn start Electron opens but there is an error in the console:

Uncaught Error: Cannot find module '/home/jp/joplin/packages/app-desktop/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node'
Require stack:
- /home/jp/joplin/packages/app-desktop/node_modules/sqlite3/lib/sqlite3-binding.js
- /home/jp/joplin/packages/app-desktop/node_modules/sqlite3/lib/sqlite3.js
- /home/jp/joplin/packages/app-desktop/index.html
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at i._resolveFilename (node:electron/js2c/renderer_init:33:1095)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at c._load (node:electron/js2c/asar_bundle:5:13343)
    at i._load (node:electron/js2c/renderer_init:33:356)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/jp/joplin/packages/app-desktop/node_modules/sqlite3/lib/sqlite3-binding.js:4:17)
    at Object.<anonymous> (/home/jp/joplin/packages/app-desktop/node_modules/sqlite3/lib/sqlite3-binding.js:7:3)
    at Module._compile (node:internal/modules/cjs/loader:1118:14)

This is on an M1 Mac.

Instead of napi-v6-darwin-unknown-arm64 I have an napi-v6-darwin-unknown-x64 directory.

So it seems that Joplin is using the correct architecture, arm64, but yarn has installed the wrong one.

I am unfamiliar with how yarn chooses which architecture to install.

Has anyone successfully built Joplin on an M1 Mac?

Thanks for contributing to a great app!

There are flags to build for M1 using npm, and there might be some for yarn too. It's not really specific to Joplin so you might have more luck on SO or the sqlite repo

You might find something useful here - ARM build for mac os M1 processor · Issue #6052 · laurent22/joplin · GitHub

Hi @laurent - thanks for your response. I am still struggling to build Joplin on my M1 Mac. When you say there are flags to build for M1 using npm, could you provide a bit more context? Where can I find these flags? I don't mind whether I build using npm or yarn, if it's easier to build using npm.

The reason I want to build Joplin is so I can contribute a fix for this issue that I raised:

Thanks,

James

I don't have an ARM Mac to test with, but this StackOverflow post might help.

The StackOverflow post uses npm. To use the --build-from-source flag with yarn, this other StackOverflow post might be helpful.

Hey @personalizedrefriger – thanks for looking at this.

It worked! Here's what I did.

$ cd ~/Code/3rd-party/joplin
$ export npm_config_build_from_source=true
$ export npm_config_target_arch=arm64
$ export npm_config_fallback_to_build=true
$ npm install sqlite3
$ cd packages/app-desktop
$ yarn start

Thanks!

1 Like