isar-community / isar

Extremely fast, easy to use, and fully async NoSQL database for Flutter
https://isar-community.dev
Apache License 2.0
126 stars 14 forks source link

Disable web for isar versión 3.x #80

Open erikmompean opened 4 months ago

erikmompean commented 4 months ago

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.

festiburgos commented 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)

vicenterusso commented 4 months ago

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?

festiburgos commented 4 months ago

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! 💯

vicenterusso commented 4 months ago

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
festiburgos commented 3 months ago

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?

vicenterusso commented 3 months ago

Yes, but I think you should add to overrides too

festiburgos commented 3 months ago

We had already tried it with the dependencies_override, but we got the same errors.

erikmompean commented 3 months ago

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

Mistic92 commented 3 months ago

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

maxluchterhand1 commented 3 months ago

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.

maxluchterhand1 commented 2 months ago

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

https://github.com/isar-community/isar/pull/88