Open erikmompean opened 4 months ago
Same problem here! We've created an .exe that edits all the long numbers of the generated *.g.dart files before the program launches on the web, so it is compiling correctly on all platforms. However, this solution is horrible
It would be super-awesome to have an Isar version 3.x that compiles on web! 🚀 (Even if it does not work there)
It would be super-awesome to have an Isar version 3.x that compiles on web! 🚀 (Even if it does not work there)
I need to understand exactly the core of the problem. You have an app the compiles to web but you have another solution for local storage just for web.
But still get problems because Isar is embedded to the app. Sounds correct?
Exactly, our app is multiplatform. We use Isar for windows/mobile and we use SharedPreferences for web (some parts are disabled on web, so this solution fits us).
💬 It was working fine with version 3.0.0-dev.8 until we've updated the Flutter version (from 3.7.0 to 3.19.6). This new Flutter version was not compatible this Isar Version (because of the analyzer), so we had upgraded the version to Isar 3.1.6
In version 3.1.6, build_runner generates the .g.dart files with this kind of code:
const BobSchema = CollectionSchema(
name: r'Bob',
id: 3446686616087529141, // <-- THIS LINE IS GENERATING TROUBLE
...
⚠️ This works on all platforms except web. It does not compile in javascript:
Error: The integer literal 3446686616087529141 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in JavaScript.
In JavaScript 3446686616087528960 is the nearest value that can be represented exactly.
Replacing the id with a shorter number (15 digits max, for example), the project started compiling again in web. However, it is not working on other platforms then (because the id is not a valid Collection Schema Id).
🤕 For this reason, we've created a script that replaces the id: 3446686616087529141,
by id: 344668661608752,//9141,
on web and replaces it back on the other platforms.
This is just a fix, but it would be fine that Isar compiles for web even if it does not work. So projects like ours would be working without patching it. Isar is an incredible database, so we want to use it in the future projects! 💯
Tks for the detailed response. Can you try this branch? At least I think it will run. (can't test it right now)
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
Thank you for your quick answer! 👏
I've tried this solution, but I'm getting some conflicts when I run the flutter pub get
command:
Resolving dependencies...
Because every version of isar_generator from git depends on isar from hosted and festina_terminal_ventas
depends on isar from git, isar_generator from git is forbidden.
So, because festina_terminal_ventas depends on isar_generator from git, version solving failed.
exit code 1
My pubspec.yaml
looks like:
dependencies:
isar:
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
path: packages/isar
isar_flutter_libs:
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
path: packages/isar_flutter_libs
...
dev_dependencies:
isar_generator:
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
path: packages/isar_generator
...
Am I adding the dependencies correctly?
Yes, but I think you should add to overrides too
We had already tried it with the dependencies_override, but we got the same errors.
Tks for the detailed response. Can you try this branch? At least I think it will run. (can't test it right now)
git: url: https://github.com/isar-community/isar.git ref: temp-fix-v3-web
Probably this will fix my issue too. I can't try because i've had the same issue as @festiburgos
Thank you for your quick answer! 👏
I've tried this solution, but I'm getting some conflicts when I run the
flutter pub get
command:Resolving dependencies... Because every version of isar_generator from git depends on isar from hosted and festina_terminal_ventas depends on isar from git, isar_generator from git is forbidden. So, because festina_terminal_ventas depends on isar_generator from git, version solving failed. exit code 1
My
pubspec.yaml
looks like:dependencies: isar: git: url: https://github.com/isar-community/isar.git ref: temp-fix-v3-web path: packages/isar isar_flutter_libs: git: url: https://github.com/isar-community/isar.git ref: temp-fix-v3-web path: packages/isar_flutter_libs ... dev_dependencies: isar_generator: git: url: https://github.com/isar-community/isar.git ref: temp-fix-v3-web path: packages/isar_generator ...
Am I adding the dependencies correctly?
I'm getting the same error
I don't get pubspec conflicts when I add all the packages to dependency_overrides
dependency_overrides:
isar:
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
path: packages/isar
isar_generator:
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
path: packages/isar_generator
isar_flutter_libs:
git:
url: https://github.com/isar-community/isar.git
ref: temp-fix-v3-web
path: packages/isar_flutter_libs
However, the ids in the generated files are still integers that are too large for javascript to handle, so the original issue persists.
I created a fix that moves the generation of the id property (which is the reason for the web issues) from compile time to run time, that should fix the issue
My app is served on multiple platforms, but in web it crashes withe the famous: Error: The integer literal 489474... can't be represented exactly in JavaScript. We just need the isar to provide some services on mobile but it crashes in web despite we are not using isar in this platform.
It could be interesting to disable isar on web in some way to prevent the error.