wizardAEI / Gomoon

Gomoon 基于大模型的桌面端效率工具
https://gomoon.top
Apache License 2.0
315 stars 30 forks source link

[Bugs] ArchLinux下编译的一些问题 #60

Closed zxp19821005 closed 6 months ago

zxp19821005 commented 7 months ago

首先非常感谢开发了这个软件包! 从微信公众号上看到了这个项目,然后我搜索了一下ArchLinux的AUR,发现没有人移植,同时在官网也没有找到Linux版本的下载地址,于是我就准备自己编译一下,结果遇到了一堆问题,现将问题反馈如下: 1、 src/main/index.tsimport icon from '../../resources/icon.png?asset'src/min/windows.tsimport trayIcon from '../../resources/icon@20.png?asset' 都指向了不存在的resources 目录,这个我通过如下命令解决了:

icotool -i 3 -x icons/icon.ico -o icons/icon.png
icotool -i 9 -x icons/icon.ico -o icons/icon@20.png
cp -r icons resources

2、.npmrc建议修改为以下内容,这样在国内可以正常编译:

registry="https://registry.npmmirror.com/"
electron_mirror="https://registry.npmmirror.com/-/binary/electron/"
electron_builder_binaries_mirror="https://registry.npmmirror.com/-/binary/electron-builder-binaries/"

3、Linux下缺少很多node_modules,建议添加:

pnpm add node-fetch apache-arrow tslib flatbuffers "@neon-rs/load" "@lancedb/vectordb-linux-x64-gnu" axios form-data \
        proxy-from-env follow-redirects builder-util-runtime debug ms sax fs-extra universalify graceful-fs jsonfile \
        lazy-val semver lru-cache combined-stream delayed-stream js-yaml mime-types mime-db asynckit

都是我编译完成后运行软件,在终端报错缺少XXX模块,然后我逐一添加的。 4、建议将package.json"electron": "28.0.0", 改为 "electron": "^28.0.0", ,以使用最新版的Electron28,大版本中的小版本应该是可以向下兼容的,至少我目前移植的所有使用Electron开发的包都是这样的。 5、最终编译成功,但是运行时依然报错:

$ ../gomoon 
A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: LRU is not a constructor
    at Object.<anonymous> (/home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/dist/linux-unpacked/resources/app.asar/node_modules/semver/classes/range.js:202:15)
    at Module._compile (node:internal/modules/cjs/loader:1271:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
    at Module.load (node:internal/modules/cjs/loader:1126:32)
    at Module._load (node:internal/modules/cjs/loader:967:12)
    at l._load (node:electron/js2c/asar_bundle:2:13642)
    at Module.require (node:internal/modules/cjs/loader:1150:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/dist/linux-unpacked/resources/app.asar/node_modules/semver/classes/comparator.js:141:15)
    at Module._compile (node:internal/modules/cjs/loader:1271:14)

我本人不是程序员,也不知道该如何解决~ 附上AUR代码(剥离了编译后的Electron28,直接使用系统自带的,减小软件体积): PKGBUILD

# Maintainer: zxp19821005 <zxp19821005 at 163 dot com>
pkgname=gomoon-git
_pkgname=Gomoon
pkgver=1.0.5.r124.gcc53874
_electronversion=28
_nodeversion=18
pkgrel=1
pkgdesc="An ai tools for everyone.一款桌面端的大模型效率工具."
arch=('x86_64')
url="https://gomoon.top/"
_ghurl="https://github.com/wizardAEI/Gomoon"
license=('Apache-2.0')
conflicts=("${pkgname%-git}")
provides=("${pkgname%-git}=${pkgver%.r*}")
depends=(
    "electron${_electronversion}"
)
makedepends=(
    'gendesk'
    'nvm'
    'npm'
    'pnpm'
    'git'
    'icoutils'
    'curl'
)
source=(
    "${pkgname//-/.}::git+${_ghurl}.git"
    "${pkgname%-git}.sh"
)
sha256sums=('SKIP'
            'dc0c5ca385ad81a08315a91655c7c064b5bf110eada55e61265633ae198b39f8')
pkgver() {
    cd "${srcdir}/${pkgname//-/.}"
    git describe --long --tags --exclude='*[a-z][a-z]*' | sed -E 's/^v//;s/([^-]*-g)/r\1/;s/-/./g'
}
_ensure_local_nvm() {
    export NVM_DIR="${srcdir}/.nvm"
    source /usr/share/nvm/init-nvm.sh || [[ $? != 1 ]]
    nvm install "${_nodeversion}"
    nvm use "${_nodeversion}"
}
build() {
    sed -e "s|@electronversion@|${_electronversion}|" \
        -e "s|@appname@|${pkgname%-git}|g" \
        -e "s|@runname@|app.asar|g" \
        -e "s|@options@||g" \
        -i "${srcdir}/${pkgname%-git}.sh"
    _ensure_local_nvm
    gendesk -f -n -q --categories="Development" --name="${_pkgname}" --exec="${pkgname%-git} %U"
    cd "${srcdir}/${pkgname//-/.}"
    export npm_config_build_from_source=true
    export ELECTRON_SKIP_BINARY_DOWNLOAD=1
    export SYSTEM_ELECTRON_VERSION="$(electron${_electronversion} -v | sed 's/v//g')"
    export npm_config_target="${SYSTEM_ELECTRON_VERSION}"
    export ELECTRONVERSION="${_electronversion}"
    export npm_config_disturl=https://electronjs.org/headers
    HOME="${srcdir}/.electron-gyp"
    pnpm config set store-dir "${srcdir}/.pnpm_store"
    pnpm config set cache-dir "${srcdir}/.pnpm_cache"
    pnpm config set link-workspace-packages true
    if [ `curl -s ipinfo.io/country | grep CN | wc -l ` -ge 1 ];then
        echo > .npmrc
        echo 'registry="https://registry.npmmirror.com/"' >> .npmrc
        echo 'electron_mirror="https://registry.npmmirror.com/-/binary/electron/"' >> .npmrc
        echo 'electron_builder_binaries_mirror="https://registry.npmmirror.com/-/binary/electron-builder-binaries/"' >> .npmrc
    else
        echo "Your network is OK."
    fi
    sed "s|--linux|--dir|g" -i package.json
    icotool -i 3 -x icons/icon.ico -o icons/icon.png
    icotool -i 9 -x icons/icon.ico -o icons/icon@20.png
    cp -r icons resources
    pnpm install
    pnpm add node-fetch apache-arrow tslib flatbuffers "@neon-rs/load" "@lancedb/vectordb-linux-x64-gnu" axios form-data \
        proxy-from-env follow-redirects builder-util-runtime debug ms sax fs-extra universalify graceful-fs jsonfile \
        lazy-val semver lru-cache combined-stream delayed-stream js-yaml mime-types mime-db asynckit
    pnpm run build:linux
}
package() {
    install -Dm755 "${srcdir}/${pkgname%-git}.sh" "${pkgdir}/usr/bin/${pkgname%-git}"
    install -Dm644 "${srcdir}/${pkgname//-/.}/dist/linux-"*/resources/app.asar -t "${pkgdir}/usr/lib/${pkgname%-git}"
    install -Dm644 "${srcdir}/${pkgname%-git}.desktop" -t "${pkgdir}/usr/share/applications"
    install -Dm644 "${srcdir}/${pkgname//-/.}/icons/icon.png" "${pkgdir}/usr/share/pixmaps/${pkgname%-git}.png"
}

gomoon.sh

#!/bin/bash
set -e
_APPDIR="/usr/lib/@appname@"
_RUNNAME="${_APPDIR}/@runname@"
_OPTIONS="@options@"
export PATH="${_APPDIR}:${PATH}"
export LD_LIBRARY_PATH="${_APPDIR}/swiftshader:${_APPDIR}/lib:${LD_LIBRARY_PATH}"
export ELECTRON_IS_DEV=0
export ELECTRON_FORCE_IS_PACKAGED=true
export NODE_ENV=production
cd "${_APPDIR}"
if [[ $EUID -ne 0 ]] || [[ $ELECTRON_RUN_AS_NODE ]]; then
    exec electron@electronversion@ "${_RUNNAME}" "${_OPTIONS}" "$@" || exit $?
else
    exec electron@electronversion@ "${_RUNNAME}" "${_OPTIONS}" --no-sandbox "$@" || exit $?
fi
zxp19821005 commented 7 months ago

顺便补充一下,如果是要编译打包Arm64版本,需要将 "@lancedb/vectordb-linux-x64-gnu" 替换为 "@lancedb/vectordb-linux-arm64-gnu" ,这个我也不知道该如何在 package.json 中去写。

wizardAEI commented 7 months ago

非常感谢您对该项目的关注!

首先关于LInux版本,由于我手边没有可以用的有图形界面的Linux机器,并且工作事务繁忙,所以确实无力去再维护一个Linux版本。但是我非常希望有朋友可以加入到贡献者行列,一起完善这个项目。

关于编译问题,可以先尝试一下 yarn dev 能否正常启动应用。

关于依赖问题我也不太清楚,应该是使用 yarn 自动安装后,你上述提到的缺失依赖和架构问题都会自动的被自动安装。(无需指明"@lancedb/vectordb-linux-x64-gnu" 或 "@lancedb/vectordb-linux-arm64-gnu", 都会在安装 vectordb 依赖时正确安装)

.npmrc 文件我已经改成了你建议的写法,非常感谢!

最后关于剥离Electron,这对于本机没有安装Electron和Chrome的朋友使用可能会造成困扰。后期在体积优化阶段,我希望是能够在不影响用户体验的情况,使用在线资源等方式下尽可能优化体积。你提到的方式我觉得可以建立一个另外的分支来让一些开发者或了解Electron的同学使用。

zxp19821005 commented 7 months ago
Error: ENOENT: no such file or directory, open '/home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/resources/assistants.json'

不知道resources中的文件在哪里可以下载? 另: 使用yarn运行yarn run build后一堆报错:

==> 正在开始 build()...
v18.19.1 is already installed.
Now using node v18.19.1 (npm v10.2.4)
Now using node v18.19.1 (npm v10.2.4)
Your network is OK.
yarn install v1.22.22
[1/4] Resolving packages...
success Already up-to-date.
$ electron-builder install-app-deps
  • electron-builder  version=24.6.4
  • rebuilding native dependencies  dependencies=sharp@0.32.6 platform=linux arch=x64
  • install prebuilt binary  name=sharp version=0.32.6 platform=linux arch=x64 napi=
Done in 0.74s.
yarn run v1.22.22
$ npm run typecheck && electron-vite build

> gomoon@1.0.7 typecheck
> npm run typecheck:node && npm run typecheck:web

> gomoon@1.0.7 typecheck:node
> tsc --noEmit -p tsconfig.node.json --composite false

src/lib/langchain.ts:161:30 - error TS6133: 'config' is declared but its value is never read.

161 export const newChatLlama = (config: { src: string; temperature: number }) => {
                                 ~~~~~~

src/main/lib/ai/tts.ts:36:25 - error TS6133: 'resolve' is declared but its value is never read.

36     return new Promise((resolve, reject) => {
                           ~~~~~~~

src/main/lib/ai/tts.ts:41:24 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(timeoutId: string | number | Timeout | undefined): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout | undefined'.
  Overload 2 of 2, '(id: number | undefined): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'number'.

41           clearTimeout(this.timer)
                          ~~~~~~~~~~

src/main/lib/ai/tts.ts:44:19 - error TS6133: 'key' is declared but its value is never read.

44         for (let [key, value] of this.executorMap) {
                     ~~~

src/main/lib/ai/tts.ts:45:17 - error TS2339: Property 'reject' does not exist on type 'Promise<any>'.

45           value.reject(`连接已关闭: ${reason} ${code}`)
                   ~~~~~~

src/main/lib/ai/tts.ts:71:24 - error TS2339: Property 'resolve' does not exist on type 'Promise<any>'.

71               executor.resolve(result)
                          ~~~~~~~

src/main/lib/ai/tts.ts:85:27 - error TS18047: 'matches' is possibly 'null'.

85           let requestId = matches.groups.id
                             ~~~~~~~

src/main/lib/ai/tts.ts:85:27 - error TS18048: 'matches.groups' is possibly 'undefined'.

85           let requestId = matches.groups.id
                             ~~~~~~~~~~~~~~

src/main/lib/ai/tts.ts:117:9 - error TS2345: Argument of type '{ resolve: (value: unknown) => void; reject: (reason?: any) => void; }' is not assignable to parameter of type 'Promise<any>'.
  Object literal may only specify known properties, and 'resolve' does not exist in type 'Promise<any>'.

117         resolve,
            ~~~~~~~

src/main/lib/ai/tts.ts:165:20 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(timeoutId: string | number | Timeout | undefined): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout | undefined'.
      Property '[Symbol.dispose]' is missing in type 'Timer' but required in type 'Timeout'.
  Overload 2 of 2, '(id: number | undefined): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'number'.

165       clearTimeout(this.timer)
                       ~~~~~~~~~~

  node_modules/@types/node/timers.d.ts:76:17
    76                 [Symbol.dispose](): void;
                       ~~~~~~~~~~~~~~~~~~~~~~~~~
    '[Symbol.dispose]' is declared here.

src/main/lib/ai/tts.ts:179:20 - error TS6133: 'resolve' is declared but its value is never read.

179       new Promise((resolve, reject) => {
                       ~~~~~~~

Found 11 errors in 2 files.

Errors  Files
     1  src/lib/langchain.ts:161
    10  src/main/lib/ai/tts.ts:36
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
zxp19821005 commented 7 months ago

顺便说明一下,剥离程序自带的Electron是ArchLinux相关打包准则中要求的,针对其他Linux发行版,并没有要求,比如Ubuntu、Debian、深度、Fedora等等。

wizardAEI commented 7 months ago

哈喽,我已经把resource资源上传到了云盘,其中包含各个架构需要的资源文件。后续也会更新readme

zxp19821005 commented 7 months ago

不知道能不能单独上传到release里面呢?这样的话我在ArchLinux下打包可以直接下载,而使用123网盘的话无法直接下载,只有转存到我自己的git仓库里面。 https://github.com/zxp19821005/My_AUR_Files/releases

wizardAEI commented 7 months ago

你尝试下载到本地,打包使用本地文件的方案呢?个人开发精力确实有限,我可以传到release上去,但不能保证后续的更新🥲

zxp19821005 commented 7 months ago

好吧 我已经上传到github了 : https://github.com/zxp19821005/My_AUR_Files/releases/tag/gomoon

zxp19821005 commented 7 months ago

yarn dev报错:

$ yarn dev
yarn run v1.22.22
$ electron-vite dev
vite v4.5.0 building for development...
✓ 27 modules transformed.
out/main/lowdb-981658c5.js   2.32 kB
out/main/index.js           53.71 kB
✓ built in 318ms

build the electron main process successfully

-----

vite v4.5.0 building for development...
✓ 1 modules transformed.
out/preload/index.js  4.47 kB
✓ built in 14ms

build the electron preload files successfully

-----

dev server running for the electron renderer process at:

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose

start electron app...

App threw an error during load
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/node_modules/node-fetch/src/index.js from /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/out/main/index.js not supported.
Instead change the require of /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/node_modules/node-fetch/src/index.js in /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/out/main/index.js to a dynamic import() which is available in all CommonJS modules.
    at l._load (node:electron/js2c/asar_bundle:2:13642)
    at Object.<anonymous> (/home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/out/main/index.js:47:15)
    at l._load (node:electron/js2c/asar_bundle:2:13642)
A JavaScript error occurred in the main process
Uncaught Exception:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/node_modules/node-fetch/src/index.js from /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/out/main/index.js not supported.
Instead change the require of /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/node_modules/node-fetch/src/index.js in /home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/out/main/index.js to a dynamic import() which is available in all CommonJS modules.
    at l._load (node:electron/js2c/asar_bundle:2:13642)
    at Object.<anonymous> (/home/zxp-endeavouros/.cache/paru/clone/gomoon-git/src/gomoon.git/out/main/index.js:47:15)
    at l._load (node:electron/js2c/asar_bundle:2:13642)
zxp19821005 commented 7 months ago

看到一个解决方案:https://stackoverflow.com/questions/72244629/replacing-js-require-with-esm-imports

wizardAEI commented 7 months ago

将 node-fetch 降低版本到:"node-fetch": "^2.6.4", 试试呢?

wizardAEI commented 7 months ago

另外上述的问题很大程度上都是因为开发过程中没有对导入依赖进行lint检查,导致出现了很多幽灵依赖。这是我的问题,后续会加入检查来强要求的!

zxp19821005 commented 7 months ago

将 node-fetch 降低版本到:"node-fetch": "^2.6.4", 试试呢?

报同样的错误。

wizardAEI commented 7 months ago

上述报错是因为最新的 node-fetch 版本已经是一个 ES 模块。此时使用编译后的代码(require('node-fetch')形式仍然了使用CommonJS)就会报错。 image 应该是可以通过降低 node-fetch 版本来解决模块问题的(降至可以使用CommonJS模块加载的版本)

wizardAEI commented 6 months ago

哈喽,请问问题解决了吗?如果可以我就关闭该issue了😇

zxp19821005 commented 6 months ago

目前已经可以运行了,谢谢!