#Importing npm modules into gleam projects

1 messages · Page 1 of 1 (latest)

merry goblet
#

I'm currently trying to use https://github.com/hayleigh-dot-dev/gleam-lustre. My naive approach of relying on the generated JS in the browser gets the following error.

Uncaught TypeError: The specifier “react” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.

I think the only solution is to js a JS build tool. looking at the example project in lustre vite is used.
Is there a way to rely on JS libraries without needing a JS build tool.

  1. Could we use ffi that pointed to the node_modules directory? so that the gleam build would copy them into the build dir
  2. Can we get npm to save files somewhere else?

Note: I have "solved" this by commenting out the react imports at the top of lustre ffi and relying on global imports. https://github.com/hayleigh-dot-dev/gleam-lustre/blob/main/src/ffi.mjs#L1-L2

Maybe this is good enough.

GitHub

A playground for building creative web apps – powered by Gleam. - gleam-lustre/ffi.mjs at main · hayleigh-dot-dev/gleam-lustre

polar moon
#

Bundling assets is the de facto way to manage dependencies so lustre was made with that use-case in mind.

If you have ideas on how to support different approaches I’d love to hear em!

charred raven
#

I made sure to find/make small projects without deps tho.

merry goblet
#

@charred raven how do you direct npm to use the priv dir when running npm i?

charred raven
#

IIRC, I run it from the priv dir.