I’ve looked at the similar issues and documentation for dynamically importing modules, but they don’t seem to work (I think they are designed to import part of an existing project).
I’m trying to dynamically import modules which are not known at compile time. Essentially, I get a string which is the URL path to a JS module, and then import it. In theory, this should be possible with the import()
function, but within a react app this seems to fail to find the module.
When loading the page, the react code errors with Error: Cannot find module '/js'
. But, in the console on the same page, I can run this without a problem: import("/js").then((mod) => console.log(mod))
This suggests to me that react is using a custom import()
function, rather than the browser supplied one. Is there a way to bypass and use the browser’s version, or some other way to get this to work dynamically with an arbitrary URL?