-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import dynamically #179
Comments
Thus, as shown above, the module is always imported, but I need to import the module by condition and from self hosting:
Thanks! |
@geshov the target at |
Have you tried I have a
Browser gives the following error:
If, as you claim, Thanks! |
I have not had the necessity to perform dynamic conditional imports, but all I'm saying is that this package exports two target versions, an ESM and a UMD. That's all the package can be responsible for, in order to be imported by the consumers. If you find something amiss in the syntax of these two exports, please report it. Otherwise there could be something wrong in the consumer import method. |
I will return to my original request, which is reflected in the title of this issue:
It was a request, not a demand, so: a) if you can help with this, then probably many will be grateful, because the library is quite large and under certain conditions it will help solve the performance problem. b) if you don't want to do this, then write about it directly, without tricks, no one will be offended, since you already share your development for free. Thanks! |
@geshov I don't mind helping where I can, but I'm just not clear on specifically how such a target will be any different than the two already exposed, ESM and UMD. |
If you can help, please make a version of the Globe.gl library that can be imported dynamically from self hosting:
Or add a working example of such an import to the documentation. Thanks! |
@gashov you can see here a working example of dynamically importing globe.gl, as an installed package in your app: https://codesandbox.io/s/globe-dynamic-import-8zyhz7?file=/src/index.mjs This uses the regular ESM target in the module. What you were missing initially is that |
I tried to repeat your code with the library
The browser gives the same error:
My code differs from yours only in that it uses the library I still don't understand - which library should I use so that I can load it from my hosting and for this example to work? Thanks! |
Do you have an app with a This is not specific to this module, it's how NPM dependencies work in general. Basically importing this package should work just like any other dependency of your app. |
Here is a link to the documentation for the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import The documentation does not say anything about the fact that dynamic import works only in the Node.js (NPM) environment and requires the presence of the package.json file. Here is an example from this documentation:
It's just a JS function, and it allows you to dynamically import modules prepared accordingly. |
I independently found a solution for dynamically importing the Globe.gl library without Node.js (NPM) and without package.json . You can close this issue, thanks! |
Please make variant of Globe.gl for the possibility of dynamic import in the browser:
const Globe = import("globe.gl.umd.js");
Thanks!
The text was updated successfully, but these errors were encountered: