silverbulletmd / silverbullet-plug-template

Template for starting a new plug
7 stars 3 forks source link

Build fails with import map issue #4

Closed Maarrk closed 2 months ago

Maarrk commented 8 months ago

Can't build the template plug, deno task build fails due to some problem with import map working relatively to SilverBullet installation URL. (same result on Windows and WSL)

full output ``` Task build silverbullet plug:compile hello.plug.yaml Building [ "hello.plug.yaml" ] ✘ [ERROR] Unexpected token '<', " (https://get.silverbullet.md/:76866:9) at handleIncomingPacket (https://get.silverbullet.md/:76925:9) at readFromStdout (https://get.silverbullet.md/:76842:7) at https://get.silverbullet.md/:78107:11 at eventLoopTick (ext:core/01_core.js:182:7) { errors: [Getter/Setter], warnings: [Getter/Setter] } Done building plugs in 649ms ```

Looking through the Plugs, I found an applicable solution in "Mattermost" (others just do ../silverbullet/plug-api/ or don't use Deno). Copying the commands from there, I can confirm that this works:

diff --git a/deno.jsonc b/deno.jsonc
index f49f823..7451999 100644
--- a/deno.jsonc
+++ b/deno.jsonc
@@ -1,8 +1,8 @@
 {
   "importMap": "import_map.json",
   "tasks": {
-    "build": "silverbullet plug:compile hello.plug.yaml",
-    "watch": "silverbullet plug:compile hello.plug.yaml -w"
+    "build": "silverbullet plug:compile --importmap import_map.json hello.plug.yaml",
+    "watch": "silverbullet plug:compile --importmap import_map.json hello.plug.yaml -w"
   },
   "lint": {
     "rules": {

I see that in theory it should work with just the importMap key, is it a Deno issue? I don't know, I'm using it first time now.

Should I do a PR with the workaround?


Huge fan of SilverBullet, hope to contribute more!

simone-viozzi commented 6 months ago

I can reproduce the issue using a dev container:

Dockerfile:

FROM denoland/deno:debian

RUN deno install -f --name silverbullet  --unstable-kv --unstable-worker-options -A https://get.silverbullet.md

CMD tail -f /dev/null

docker-compose

  deno-silverbullet-plug:
    build: .
    volumes:
      - ./plug-template:/plug

output

# deno task build
Task build silverbullet plug:compile hello.plug.yaml
Building [ "hello.plug.yaml" ]
✘ [ERROR] Unexpected token '<', "<!DOCTYPE "... is not valid JSON [plugin deno-resolver]

error: Unable to load 'https://get.silverbullet.md/import_map.json' import map

Caused by:
    Import 'https://get.silverbullet.md/import_map.json' failed, not found.
✘ [ERROR] Failed to call 'deno info' on 'file:///tmp/164487b1a93cc664.js' [plugin deno-loader]

Error building hello.plug.yaml: Error: Build failed with 2 errors:
error: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
error: Failed to call 'deno info' on 'file:///tmp/164487b1a93cc664.js'
    at BG (https://get.silverbullet.md/:175:56)
    at https://get.silverbullet.md/:168:14432
    at E (https://get.silverbullet.md/:168:21491)
    at M (https://get.silverbullet.md/:168:14382)
    at https://get.silverbullet.md/:168:14720
    at B.<computed> (https://get.silverbullet.md/:168:9567)
    at A (https://get.silverbullet.md/:168:10357)
    at d (https://get.silverbullet.md/:168:9267)
    at https://get.silverbullet.md/:175:5633
    at eventLoopTick (ext:core/01_core.js:169:7) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}
Done building plugs in 2921ms
Maarrk commented 2 months ago

Implemented in db6841d