pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.25k stars 61 forks source link

"assets.deploy" will throw an error on Prod server #232

Closed tabatinga0xffff closed 9 months ago

tabatinga0xffff commented 10 months ago

I'm building it manually, without a docker on a server, with ENV=prod, MIX_ENV=prod, NODE_ENV=production

$ [...............]

$ mix assets.deploy

✘ [ERROR] Could not resolve "@editorjs/editorjs"

    js/campaign-editors/block/index.js:1:21:
      1 │ import EditorJS from "@editorjs/editorjs"
        ╵                      ~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@editorjs/editorjs" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Could not resolve "@editorjs/editorjs"

    js/campaign-editors/block/blocks/layout/index.js:1:21:
      1 │ import EditorJS from "@editorjs/editorjs"
        ╵                      ~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@editorjs/editorjs" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Could not resolve "punycode"

    node_modules/markdown-it/lib/index.js:14:27:
      14 │ var punycode     = require('punycode');
         ╵                            ~~~~~~~~~~

  The package "punycode" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error.

3 errors
** (Mix) `mix esbuild default --minify-whitespace --minify-identifiers --minify-syntax` exited with 1

How to fix it?

mix:

{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},

config.exs:

config :esbuild,
      version: "0.19.2",
      default: [
        args: ~w(
          js/app.js
          --bundle
          --target=es2017
          # --loader:.js=jsx
          --outdir=../priv/static/js
        ),
        cd: Path.expand("../assets", __DIR__),
        env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ]
tabatinga0xffff commented 9 months ago

If I mark @editorjs/editorjs as external, this will then bring other issues.

All in all, how could it even work? As I've found out, an npm module which is @editorjs/editorjs can't be --bundled with esbuild to work in the browser.

tabatinga0xffff commented 9 months ago

Only if I revert to

 "@editorjs/editorjs": "git+https://github.com/pentacent/editor.js.git#ff6e6ac3272f29e02229cd97ebffa5acf6c0e0fe",

will the editor start to compile and work.

How do this branch and commit differ from the upstream?