-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
"default" is not exported by "../../../Dexie.js/dist/dexie.min.js", imported by "../../../Dexie.js/import-wrapper-prod.mjs". #1995
Comments
How does the non-working package.json look? When I look at current one, it has
Seems identical? |
It was a couple months back when the issue cropped in when the wrapper was introduced, I figured it would come up and get fixed with the release of 4. I went through our code and made sure all the imports were consistent. since I've seen this sort of error with libraries that dont have default exports and not using the * notation for the import. import * as xyx from 'lib', but Dexie has default exports. so were using import Dexie from 'dexie' |
Tried to reproduce just now: https://github.com/dfahlander/dexie-vite-starter But I saw there was an issue in vite vitejs/vite#2679 Which version of vite are you using? |
If we do, nextjs apps suffer from double instanciating the dexie module (for some reason) and that causes problems as it has static properties that must be singleton instance. Ideally one should isolate state into a stateful module and import that one only as commonjs and the rest as ES. |
I think I have it. my project is pure ESM As per https://nodejs.org/api/packages.html#dual-package-hazard
your load in the wrapper needs to be expliclity [.cjs] in order for this technique not to blow up on pure ES projects. Which is why its importing as a ES and not commonjs resulting in default export not found. |
Thanks for this finding. Not sure how to properly proceed though. The path dist/dexie.min.js is expected to be there by other docs and samples, for example when including dexie in a legacy script include. I wonder if adding {"type": "commonjs"} in dexie's package.json would fix it. However, I would suppose "commonjs" is the default when "type" isn't specified so I'm not sure why vite is applying your project's "type" into dexie's type... I would suppose that vite is doing it wrong in that respect. This is a really mined area where any change can get things blown up for various configurations. I really regret adopting es module format too early, it has cause so much problems so far. |
Here is the rub, We unlinked from our fork https://github.com/metafig/Dexie.js and reverted to the npm release. (built and ran as expected) It must be something specific to loading directly off the locally built fork. (Which sucks cause it hinders our ability to help contribute to issues.) Were still running off our fork https://github.com/metafig/dexie-encrypted so we can keep that project moving forward. I added the local pnpm link into your starter project and it failed as expected. |
I see. Seems as a vite bug then. Would it be a way forward if your fork of Dexie.js would have a step in its build process to copy dexie.min.js to dexie.min.cjs and change package.json? |
I confirmed the linking issue , set up a clean new fork under our launch organization Funny Enough you ask about that , We went as far as renaming all the release files to .cjs and modifying the wrappers etc. Everything built fine, BUT ... When we ran the SPA when the browser went to load the wrapper file it reported that the default export was not there at runtime. Just pushed the issue down the road. Vite is definitely may not be doing something during the packing to handling this commonjs wrapper node hack for dual environments. OR the local build is somehow different than the release build? Honestly I'm a bit baffled with how it's all getting loaded etc. and why is the release build is working ! |
Getting the same error here using rollup (in esm only mode) directly. Could you maybe just add |
I have the same problem in a pure ESM project, no frameworks or packaging involved. I just updated from 3.2.2 to 4.0.7, now I am getting
in the browser console. |
Pure esm cannot load cjs modules. Import-wrapper is a workaround for node-based clients to avoid dual package hazard. For pure esm clients, import dist/dexie.mjs or dist/modern/dexie.mjs |
Not sure to understand, is there a solution to this problem? I need to maintain my own fork, at least until #1973 gets merged, and I have no idea how to make |
change your imports from |
Great thanks a lot, I thought this would only apply for a specific way of compiling… And it actually solves multiple weird bugs, including a really weird bug that my system was not using the proper Dexie version. I actually changed it globally by adding in my vite.config.ts:
Thanks! |
When building via Vite. Getting
x Build failed in 8.15s error during build: RollupError: [vite-plugin-pwa:build] ../../../Dexie.js/import-wrapper-prod.mjs (4:7): "default" is not exported by "../../../Dexie.js/dist/dexie.min.js", imported by "../../../Dexie.js/import-wrapper-prod.mjs". file: /Users/nlaurie/Development/metafig/Dexie.js/import-wrapper-prod.mjs:4:7
Everything go back to building fine when I revert to a previous package.json that looks like this
"production": { "module": "./import-wrapper-prod.mjs", "import": "./import-wrapper-prod.mjs", "require": "./dist/dexie.min.js", "default": "./dist/dexie.min.js" },
The text was updated successfully, but these errors were encountered: