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
Cannot import local forage through Javascript ES6 #976
Comments
This comment has been minimized.
This comment has been minimized.
Can you post a full example—perhaps a repo we can use to diagnose the problem? Sounds like you might have a webpack config that isn't working or something, as importing localForage with that import syntax has been known to work without issue for some time. |
I think that bug is unrelated, see #979. If it still happens with 1.8.1 please let us know 😄 |
Example in 1.9.0, all vanilla ES6 import, using a single HTML file: <script type="module">
import localforage from "../node_modules/localforage/dist/localforage.js";
</script> result: <script type="module">
import * as localforage from "../node_modules/localforage/dist/localforage.js";
localforage.setItem('key', 'value')
</script> result: <script type="module">
import localforage from "../node_modules/localforage/src/localforage.js";
</script> result: |
A mere |
@madeInLagny It works if you use a module loader that handles node_modules, like webpack, Parcel, Vite or Rollup with the plugin @rollup/plugin-node-resolve. Browsers do not handle node_modules and, as many people nowadays are developing applications without using the tools above, would be nice if it was possible to import the module directly from the browser. You can run One thing focalForage contributors can do is releasing a browser compatible ES version of the library bundled into a single file. Vite does that to improve performance. By doing is possible to import the module directly in a modern browser fetching just one file and anyone using a bundler can still use the library as usual. The hard thing is setting up the package.json so it don't break webpack, as happened with some libraries (I remember Mithril) when those started releasing ESM builds. |
Why is this still an issue... |
Agreed—this is not a bug so I'm closing it. 👍🏻 |
While it is not a bug, it would be nice to be able to import it in Javascript ES6. This is not possible atm as the package is not exported for ES6.(unless you already did in meantime) check this link for more details on exporting for ES6... |
Still happening in current localForage, see #831 for some workarounds |
I'm attempting to import localForage in vanilla Javascript using
import localforage from "localforage";
which results in the error
SyntaxError: Importing binding name 'default' cannot be resolved by star export entries.
Doing it this way,
TypeError: undefined is not a function (near '...localforage.config...')
will not error initially but I cannot use the config() function as the error occurs
TypeError: undefined is not a function (near '...localforage.config...')
The text was updated successfully, but these errors were encountered: