-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Description
Hi 👋
I'm working on implementing Vue.js SSR for Phoenix.
To bundle server code, I'm using Vite. Sadly, it only generated ESM modules (using import / export, not require).
Currently, elixir-nodejs always require files, thus making it impossible to call functions inside ESM modules.
Solution
I'll implement import inside server.js and let it be used by specifying esm: true in opts, like this:
# extension is required in ESM imports
NodeJS.call({"esm-module.js", :uuid}, [], esm: true)
# if using mjs extension esm: true will be automatically set
NodeJS.call({"esm-module.mjs", :uuid})
# to force module reload, add a cache busting string
NodeJS.call({"esm-module.mjs?q=#{System.unique_integer()}", :uuid})Caveats
- Extension is always required in ESM imports, if not importing package from node_modules.
NODE_PATHis not respected by imports. It would need to be manually implemented- there is no cache that could be busted between imports. There's a hack of adding
?update=RANDOMquery string to import, but I believe it should be caller responsibility to do it, if necessary.
Metadata
Metadata
Assignees
Labels
No labels