thheller / shadow-cljs

ClojureScript compilation made easy
https://github.com/thheller/shadow-cljs
Eclipse Public License 1.0
2.23k stars 173 forks source link

Cannot use the @ffmpeg/ffmpeg NPM package: Errors encountered while trying to parse file #1154

Closed JordanSkousen closed 8 months ago

JordanSkousen commented 9 months ago

Hi,

I'm trying to use the @ffmpeg/ffmpeg NPM package in my project (which is from the ffmpeg.wasm project). After requiring it in my project I am given the error:

[:browser] Build failure:
Failed to inspect file
  <project location>/node_modules/@ffmpeg/ffmpeg/dist/umd/ffmpeg.js

Errors encountered while trying to parse file
  <project location>/node_modules/@ffmpeg/ffmpeg/dist/umd/ffmpeg.js
  {:line 1, :column 1741, :message "'}' expected"}

I tried using this package in a plain React project and it works just fine, so I don't think it's a problem with the package itself.


In case you need them, here's my shadow-cljs.edn file:

{:deps      {:aliases [:dev]}
 :autobuild true
 :nrepl     {:port 3333}
 :dev-http  {3000 ["resources/public"]}
 :builds    {:browser         {:target           :browser
                               :modules          {:test {:entries [test.core]
                                                         :init-fn test.core/init}}
                               :output-dir       "resources/public/js"
                               :asset-path       "/js"}}}

And deps.edn file:

{:deps    {thheller/shadow-cljs        {:mvn/version "2.25.8"}
           reagent/reagent             {:mvn/version "1.2.0"
                                        :exclusions  [cljsjs/react cljsjs/react-dom]}}
 :aliases {:dev {:extra-deps {org.clojure/clojure {:mvn/version "1.11.1"}}}}}

And src/test/core.cljs file:

(ns test.core
  (:require [reagent.dom :as rdom]
            ["@ffmpeg/ffmpeg" :as FFmpeg]))

(defn ^:dev/after-load mount-root []
  (rdom/render [:h1 "Hi"] (.getElementById js/document "app")))

(defn ^:export init []
  (mount-root))
thheller commented 9 months ago

The packages is using syntax (e.g. this.#i) that is currently not supported by the closure compiler.

See https://github.com/google/closure-compiler/issues/2731

Unfortunately that is not something I can change from the shadow-cljs side. Therefore I cannot give an estimate when this might work. You can fallback to use webpack (or similar) to take care of the JS bundling via :js-provider :external.

JordanSkousen commented 8 months ago

Thanks for the quick response. I see if I can recompile this package to not use that kind of syntax.