This is probably a basic question, sorry for that; I am not an experienced client-side programmer.
How can I make a node HTML script load a .js module? I am developing a node-red package. The HMTL script files of several of the nodes in the package need the same javascript functions. I would like to put them in a common .js file and have the scripts load that file.
I tried inserting the following line in the script: import { foo} from './module.js'
but this doesn't does work.
I also tried adding the following line in the HTML files: <script type="module" src="module.js"></script>
I can see on the browser console that the browser refuses to load the .js file because of a MIME type issue. Loading module from “http://127.0.0.1:1880/module.js” was blocked because of a disallowed MIME type (“text/html”).
There is a more fundamental issue here. There's nothing in the runtime that knows how to serve up the extra .js file to the browser. So whether it's a module/import or not is actually irrelevant.
To get this to work, you'd have to add a custom admin endpoint to your node that can be used to serve up the extra content.
Thanks a lot. I did vaguely suspect there was something needed to get this file properly served.
Reading the geofence code, I also realize I don't really know exactly what the object RED is but I can't find it referred to in the available doc.
Do you mind indicating where to look for some explanation ?
Thanks.