toeverything / AFFiNE

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
https://affine.pro
Other
41.4k stars 2.69k forks source link

desktop application doesn't run when build is completed #6645

Closed mirtaqi07 closed 6 months ago

mirtaqi07 commented 6 months ago

What happened?

I am trying to build the desktop application by running yarn make in packages/frontend/electron, it builds the artifacts but when I open the exe, following error shows up saying can't find electron-updater but electron-updater is in the node modules although the yarn install was a success. I couldn't figure out, kindly help me to build the desktop app.

1

Distribution version

Windows x64

What browsers are you seeing the problem on if you're using web version?

No response

Are you self-hosting?

Relevant log output

E:\AFFiNE\packages\frontend\electron>yarn make
(node:7940) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm/transpile-only", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
√ Checking your system
(node:7748) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm/transpile-only", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
√ Loading configuration
√ Resolving make targets
√ Loading configuration
√ Resolving make targets
  › Making for the following targets: ,
√ Running package command
  √ Preparing to package application
  √ Running packaging hooks
    √ Running generateAssets hook
      √ Running generateAssets hook from forgeConfig
    √ Running prePackage hook
      √ Running prePackage hook from forgeConfig
  √ Packaging application
    √ Packaging for x64 on win32 [4m29s]
  √ Running postPackage hook
√ Running preMake hook
√ Making distributables
  √ Making a zip distributable for win32/x64 [32s]
  √ Making a squirrel distributable for win32/x64 [1m56s]
√ Running postMake hook
  › Artifacts available at: E:\AFFiNE\packages\frontend\electron\out\canary\make

E:\AFFiNE\packages\frontend\electron>

Anything else?

No response

affine-issue-bot[bot] commented 6 months ago

Issue Status: 🆕 *Untriaged

*🆕 Untriaged**

The team has not yet reviewed the issue. We usually do it within one business day. Docs: https://github.com/toeverything/AFFiNE/blob/canary/docs/issue-triaging.md

This is an automatic reply by the bot.

pengx17 commented 6 months ago

Due to some issues on the package manager (hoisting) + electron compatibility issues, the electron build will be done in two stages.

  1. build frontend (with default yarn settings)
  2. build electron (reinstall with hoisting off)

Below is a script that I used for debugging build issues on MacOS. I think you can easily adopt it for windows as well.

#!/bin/bash

echo "step 1: clean up"
find . -name "node_modules" -prune -exec rm -rf '{}' +
# git clean -dfX
git checkout .
build_type=canary

echo "step 2: install web dependencies"
# firstly, build web static
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 SENTRYCLI_SKIP_DOWNLOAD=1 PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=1 yarn

echo "step 3: generate assets"
BUILD_TYPE="$build_type" yarn workspace @affine/electron generate-assets

# cleanup node_modules
find . -name "node_modules" -prune -exec rm -rf '{}' +

echo "step 4: install electron dependencies"
# install electron deps
yarn config set nmHoistingLimits workspaces
yarn config set enableScripts false
yarn config set nmMode classic
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn workspaces focus @affine/electron @affine/monorepo

echo "step 5: build native"
# build native
yarn workspace @affine/native build
yarn workspace @affine/storage build

echo "step 6: build electron"
# build electron
yarn workspace @affine/electron build

echo "step 7: package electron"
# package
SKIP_GENERATE_ASSETS=1 BUILD_TYPE="$build_type" HOIST_NODE_MODULES=1 yarn workspace @affine/electron package
mirtaqi07 commented 6 months ago

Thanks. I've tried cleared all the cache and follow the instructions. At yarn workspace @affine/storage build,

F:\AFFiNE>yarn workspace @affine/storage build Compiling cfg-if v1.0.0 Compiling windows_x86_64_msvc v0.48.5 Compiling syn v2.0.38 Compiling libm v0.2.8 Compiling getrandom v0.2.10 Compiling windows-targets v0.48.5 Compiling num-traits v0.2.17 Compiling once_cell v1.18.0 Compiling rand_core v0.6.4 Compiling typenum v1.17.0 Compiling ppv-lite86 v0.2.17 Compiling generic-array v0.14.7 Compiling rand_chacha v0.3.1 Compiling smallvec v1.11.1 Compiling radium v0.7.0 Compiling zerocopy v0.7.31 Compiling serde v1.0.193 Compiling scopeguard v1.2.0 Compiling lock_api v0.4.11 Compiling ahash v0.8.6 Compiling serde_derive v1.0.193 Compiling parking_lot_core v0.9.9 Compiling rand v0.8.5 Compiling windows-sys v0.48.0 Compiling hashbrown v0.14.2 Compiling tap v1.0.1 Compiling wyz v0.5.1 Compiling libloading v0.8.1 Compiling dashmap v5.5.3 Compiling hashbrown v0.13.2 Compiling thiserror-impl v1.0.50 Compiling block-buffer v0.10.4 Compiling crypto-common v0.1.6 Compiling itoa v1.0.9 Compiling pin-project-lite v0.2.13 Compiling num_cpus v1.16.0 Compiling ryu v1.0.15 Compiling memchr v2.6.4 Compiling funty v2.0.0 Compiling minimal-lexical v0.2.1 Compiling thiserror v1.0.50 Compiling bitvec v1.0.1 Compiling nom v7.1.3 Compiling napi-derive-backend v1.0.59 Compiling affine_storage v1.0.0 (F:\AFFiNE\packages\backend\storage) Compiling tokio v1.34.0 Compiling serde_json v1.0.108 Compiling digest v0.10.7 Compiling lasso v0.7.2 Compiling napi-sys v2.3.0 Compiling nanoid v0.4.0 Compiling rand_distr v0.4.3 Compiling ordered-float v4.1.1 Compiling ctor v0.2.5 Compiling bitflags v2.4.1 Compiling byteorder v1.5.0 Compiling log v0.4.20 Compiling keccak v0.1.4 Compiling smol_str v0.2.1 Compiling napi v2.14.1 Compiling sha3 v0.10.8 Compiling napi-derive v2.15.0 Compiling y-octo v0.0.1 (https://github.com/y-crdt/y-octo.git?branch=main#01ec08ac) Compiling chrono v0.4.31 error: expected item, found .. --> packages\backend\storage\src\hashcash.rs:1:1 1 ../../../frontend/native/src/hashcash.rs ^^ expected item

= note: for a full list of items that can appear in modules, see https://doc.rust-lang.org/reference/items.html

error: could not compile affine_storage (lib) due to 1 previous error Internal Error: Build failed with exit code 101 at ChildProcess. (file:///F:/AFFiNE/node_modules/@napi-rs/cli/dist/api/build.js:184:28) at Object.onceWrapper (node:events:629:26) at ChildProcess.emit (node:events:526:35) at ChildProcess._handle.onexit (node:internal/child_process:294:12)

F:\AFFiNE>

pengx17 commented 6 months ago

Oh, I forgot that you also need to install rust toolchain and then run yarn workspace @affine/storage build and yarn workspace @affine/native build before running make for the electron module

mirtaqi07 commented 6 months ago

it is installed in my system. Can you plz build in your system and tell me the steps. I'm stuck here for days.

image

pengx17 commented 6 months ago

Oh, sorry I missed the log you pasted. The issue here is that on Windows you may need to turn on symlink for git, otherwise packages/backend/storage/src/hashcash.rs will not be correctly be read from git. You can turn it on by running

  1. remove your packages/backend/storage/src/hashcash.rs from your local machine
  2. git config --global core.symlinks true
  3. git checkout packages/backend/storage/src/hashcash.rs

Afterwards you can try build storage and native package again.

mirtaqi07 commented 6 months ago

I've done that, but still the error is same.

F:\AFFiNE>git config --get core.symlinks false

F:\AFFiNE>git checkout packages/backend/storage/src/hashcash.rs Updated 1 path from the index

Details F:\AFFiNE>yarn workspace @affine/storage build Compiling cfg-if v1.0.0 Compiling windows_x86_64_msvc v0.48.5 Compiling getrandom v0.2.10 Compiling windows-targets v0.48.5 Compiling once_cell v1.18.0 Compiling rand_core v0.6.4 Compiling typenum v1.17.0 Compiling ppv-lite86 v0.2.17 Compiling smallvec v1.11.1 Compiling zerocopy v0.7.31 Compiling rand_chacha v0.3.1 Compiling scopeguard v1.2.0 Compiling generic-array v0.14.7 Compiling lock_api v0.4.11 Compiling ahash v0.8.6 Compiling rand v0.8.5 Compiling parking_lot_core v0.9.9 Compiling windows-sys v0.48.0 Compiling block-buffer v0.10.4 Compiling dashmap v5.5.3 Compiling crypto-common v0.1.6 Compiling hashbrown v0.13.2 Compiling minimal-lexical v0.2.1 Compiling libloading v0.8.1 Compiling itoa v1.0.9 Compiling pin-project-lite v0.2.13 Compiling num_cpus v1.16.0 Compiling ryu v1.0.15 Compiling tokio v1.34.0 Compiling nom v7.1.3 Compiling serde_json v1.0.108 Compiling lasso v0.7.2 Compiling napi-sys v2.3.0 Compiling rand_distr v0.4.3 Compiling nanoid v0.4.0 Compiling digest v0.10.7 Compiling log v0.4.20 Compiling bitflags v2.4.1 Compiling keccak v0.1.4 Compiling napi v2.14.1 Compiling y-octo v0.0.1 (https://github.com/y-crdt/y-octo.git?branch=main#01ec08ac) Compiling sha3 v0.10.8 Compiling chrono v0.4.31 Compiling affine_storage v1.0.0 (F:\AFFiNE\packages\backend\storage) error: expected item, found `..` --> packages\backend\storage\src\hashcash.rs:1:1 | 1 | ../../../frontend/native/src/hashcash.rs | ^^ expected item | = note: for a full list of items that can appear in modules, see error: could not compile `affine_storage` (lib) due to 1 previous error Internal Error: Build failed with exit code 101 at ChildProcess. (file:///F:/AFFiNE/node_modules/@napi-rs/cli/dist/api/build.js:184:28) at Object.onceWrapper (node:events:629:26) at ChildProcess.emit (node:events:526:35) at ChildProcess._handle.onexit (node:internal/child_process:294:12) F:\AFFiNE>

And do you think that this error could cause the exe upon yarn make to not open which gives this error.

image

pengx17 commented 6 months ago

Sorry, i made a mistake about the git command you should use, which should be git config core.symlinks true. After turning symlink on, you can then run git checkout packages/backend/storage/src/hashcash.rs and try to build storage & native again.

The issue in your screenshot looks like you did not disable hoisting for the packager manager. As I said earlier:

Due to some issues on the package manager (hoisting) + electron compatibility issues, the electron build will be done in two stages.

  • build frontend (with default yarn settings)
  • build electron (reinstall with hoisting off)

Between each build steps, you have to remove all node_modules (including nested one)

You need to follow https://github.com/toeverything/AFFiNE/issues/6645#issuecomment-2068367804 carefully.

mirtaqi07 commented 6 months ago

I followed these; the final build didn't give any error, but the app is stuck & displays nothing. Kindly correct me what I've done wrong.

# these to build the frontend
yarn install
yarn run dev
yarn workspace @affine/native build
yarn run dev:electron

Then these steps;

# these to build the electron
@echo off

echo step 1: clean up...
for /d /r .\ %%i in (node_modules) do if exist "%%i" rd /s /q "%%i"
git checkout .
set build_type=canary

echo step 2: install web dependencies
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
set SENTRYCLI_SKIP_DOWNLOAD=1
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
set HUSKY=1 
yarn

echo step 3: generate assets
set BUILD_TYPE=%build_type%
yarn workspace @affine/electron generate-assets

# cleanup node_modules
for /d /r .\ %%i in (node_modules) do if exist "%%i" rd /s /q "%%i"

echo step 4: install electron dependencies
yarn config set nmHoistingLimits workspaces
yarn config set enableScripts false
yarn config set nmMode classic
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
set HUSKY=0
yarn workspaces focus @affine/electron @affine/monorepo

echo step 5: build native
git config core.symlinks true
git checkout packages/backend/storage/src/hashcash.rs

yarn workspace @affine/native build
yarn workspace @affine/storage build

echo step 6: build electron
yarn workspace @affine/electron build

echo step 7: package electron
set SKIP_GENERATE_ASSETS=1
set BUILD_TYPE=%build_type%
set HOIST_NODE_MODULES=1
yarn workspace @affine/electron package

Initially I got the error at yarn workspace @affine/storage build while using yarn workspaces focus @affine/electron @affine/monorepo

Error

D:\AFFiNE>yarn workspace @affine/storage build 'napi' is not recognized as an internal or external command, operable program or batch file. command not found: napi

Then I followed the same procedure with yarn add instead of yarn workspaces focus @affine/electron @affine/monorepo and didn't get that napi error.

So, at the end, the build was success with yarn workspace @affine/electron package and it didn't give that previous error on opening the exe. But the software somehow is stuck, and it displays nothing.

Software

1713973400607

Task Manager

1

mirtaqi07 commented 6 months ago

@pengx17 I've tried again today from start, but its same; the final app is stuck. I don't know what I'm doing wrong. Kindly help me.