Excalidraw en un jail

logo

Vamos a configurar un jail para instalar excalidraw en local y solucionar el problema de aquitectura para FreeBSD.

Creamos el jail primero con Bastille he añadido en el jails.conf las líneas típicas

allow.mlock;
allow.raw_sockets;

Instalando Excalidraw

Según en su web los pasos siguientes deberían de funcionar pero tenemos errores, en mi caso sobre la arquitectura, al intentar arrancar con yarn.

Fallo del yarn start

Justo esto es un error presente

Error: Your current platform "freebsd" and architecture "x64" combination is not yet supported by the native Rollup build. Please use the WASM build "@rollup/wasm-node" instead.
yarn start
yarn run v1.22.19
$ yarn --cwd ./excalidraw-app start
$ yarn && vite
[1/5] Validating package.json...
[2/5] Resolving packages...
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^3.0.0"
success Already up-to-date.
/root/excalidraw/node_modules/vite/node_modules/rollup/dist/native.js:84
	throw new Error(
	      ^

Error: Your current platform "freebsd" and architecture "x64" combination is not yet supported by the native Rollup build. Please use the WASM build "@rollup/wasm-node" instead.

The following platform-architecture combinations are supported:
android-arm
android-arm64
darwin-arm64
darwin-x64
linux-arm
linux-arm (musl)
linux-arm64
linux-arm64 (musl)
linux-ppc64
linux-riscv64
linux-s390x
linux-x64
linux-x64 (musl)
win32-arm64
win32-ia32
win32-x64

If this is important to you, please consider supporting Rollup to make a native build for your platform and architecture available.
    at throwUnsupportedError (/root/excalidraw/node_modules/vite/node_modules/rollup/dist/native.js:84:8)
    at getPackageBase (/root/excalidraw/node_modules/vite/node_modules/rollup/dist/native.js:75:3)
    at Object.<anonymous> (/root/excalidraw/node_modules/vite/node_modules/rollup/dist/native.js:37:21)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:203:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)

Node.js v18.20.6
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Updateando el package.json

Cuando usamos yarn, debemos editar nuestro package.json y añadir lo siguente:

"resolutions": {
  "@types/react": "18.2.0",
  "strip-ansi": "6.0.1",
  "rollup": "npm:@rollup/wasm-node" (1)
}
1 Esta línea debemos añadirla.
"rollup": "npm:@rollup/wasm-node"

Aquí se está redirigiendo rollup a un paquete específico en npm llamado @rollup/wasm-node. Esto significa que, en lugar de instalar la versión estándar de rollup, se usará la versión empaquetada como @rollup/wasm-node (probablemente optimizada para entornos que usan WebAssembly o Node.js).

Es necesario borrar el directorio node_modules y el yarn.lock una vez añadida la línea anterior del wasm

Hacerlo disponible en red local

yarn start
yarn run v1.22.19
$ yarn --cwd ./excalidraw-app start
$ yarn && vite
[1/5] Validating package.json...
[2/5] Resolving packages...
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^3.0.0"
success Already up-to-date.
                                                                                                                                                                     18:37:39
  VITE v5.0.12  ready in 2036 ms

(1)
  ➜  Local:   http://localhost:3000/                                                                                                                                 18:37:39
  ➜  Network: use --host to expose                                                                                                                                   18:37:39
  ➜  press h + enter to show help                                                                                                                                    18:37:39
node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'http://localhost:3000/' ]
}

Node.js v18.20.6
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
1 Esta línea podria salir, porque faltaría simplemente hacer un yarn start --host para que puede estar disponible en nuestra red local.

Problemas con el xdg-open

Por lo visto el problema puede persistir por el xdg-open que intenta abrir el excalidraw con el browser, pero no lo tenemos instalado, podriamos solucionar instalandolo o ignorando su uso por medio de un parametro al yarn.

yarn start --host
yarn run v1.22.19
$ yarn --cwd ./excalidraw-app start --host
$ yarn && vite --host
[1/5] Validating package.json...
[2/5] Resolving packages...
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^7.0.1"
warning Resolution field "strip-ansi@6.0.1" is incompatible with requested version "strip-ansi@^3.0.0"
success Already up-to-date.
                                                                                                                                                                     18:38:15
  VITE v5.0.12  ready in 1996 ms

  ➜  Local:   http://localhost:3000/                                                                                                                                 18:38:15
  ➜  Network: http://192.168.1.28:3000/                                                                                                                              18:38:15
  ➜  press h + enter to show help                                                                                                                                    18:38:15
node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT (1)
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'http://localhost:3000/' ]
}

Node.js v18.20.6
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
1 Esta línea es un error que debemos resolver.

Como resolver el fuck xdg-open

yarn start --host --no-open (1)
1 Modo sin browser y que no intente abrir la url, permitiendo el arranque del excalidraw.

O, si no usamos, el parametro --no-open tendremos que instalarlo

pkg install xdg-utils-1.1.3_4

Luego intentamos nuevamente yarn start --host y deberia de arrancar excalidraw

Añadiendo excalidraw para el arranque

En el rc.d creamos nuestro fichero con permisos de ejecucion excalidraw para poder iniciarlo con tranquilidad ajjaja…​

#!/bin/sh

# PROVIDE: excalidraw
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="excalidraw"
rcvar="excalidraw_enable"

start_cmd="${name}_start"
stop_cmd=":"

excalidraw_start() {
    echo "Iniciando Excalidraw..."
    cd /root/excalidraw || exit 1
    (1)
    su -m root -c "env PATH=/usr/local/bin:/usr/bin:/bin /usr/local/bin/yarn start --host --no-open > /var/log/excalidraw.log 2>&1 &" (2)
}

load_rc_config $name
: ${excalidraw_enable:=no}
run_rc_command "$1"
1 Esto así, porque el yarn nos exiguira node.
2 El fichero /var/log/excalidraw.log nos dira algo en caso de error.