Skip to content
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

fflate.decompressSync is not a function when using nifti-reader-js (React) #193

Closed
pcanas opened this issue Dec 7, 2023 · 7 comments
Closed

Comments

@pcanas
Copy link

pcanas commented Dec 7, 2023

How to reproduce

  1. Clone this repo: https://github.com/Chesneynl/nifti-loader-with-error
  2. yarn install
  3. yarn dev

package.json dependencies are

    "fflate": "^0.8.1",
    "nifti-reader-js": "^0.6.8",

The problem

We get an error because the fflate functions are not found

Captura de pantalla 2023-12-07 a las 19 23 13 Captura de pantalla 2023-12-07 a las 19 24 11

These are found when I am navigating my project, so it might have to do with the bundling...

@101arrowz
Copy link
Owner

This is most likely an issue with the bundler. Webpack's tree shaking has always been a bit suspicious - I'll look into what specifically is causing this.

@pcanas
Copy link
Author

pcanas commented Dec 15, 2023

@101arrowz any updates?

@101arrowz
Copy link
Owner

This will take me a few more weeks to get to, sorry for the delay!

@gosvig123
Copy link

@101arrowz , thanks for looking into this and happy new year.
Just wanted to check in to see if you had any more context on this?

@pcanas
Copy link
Author

pcanas commented Jan 23, 2024

This will take me a few more weeks to get to, sorry for the delay!

@101arrowz Hi, any updates? Thanks!

@101arrowz
Copy link
Owner

101arrowz commented Feb 5, 2024

Looking into it now. This seems like a Webpack misconfiguration; the require("fflate") call in nifti.js is somehow resolving to a URL in the build (i.e. the string '/static/media/index.145014fd129508e7ec84.cjs' instead of the contents of that file, i.e. the JS module). I'll look into this further to see if this is something that can be easily fixed.

@101arrowz
Copy link
Owner

Yeah, this is an upstream bug with create-react-app. This can be fixed by using react-app-rewired as suggested here: facebook/create-react-app#12021 (comment). Here's a diff of what I did to fix it:

diff --git a/config-overrides.js b/config-overrides.js
new file mode 100644
index 0000000..7065965
--- /dev/null
+++ b/config-overrides.js
@@ -0,0 +1,11 @@
+module.exports = {
+  webpack: function (config, env) {
+    config.module.rules = config.module.rules.map(rule => {
+      if (rule.oneOf instanceof Array) {
+        rule.oneOf[rule.oneOf.length - 1].exclude = [/\.(js|mjs|jsx|cjs|ts|tsx)$/, /\.html$/, /\.json$/];
+      }
+      return rule;
+    });
+    return config;
+  },
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 3861681..abfa3be 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "vanilla-basic",
   "version": "1.0.0",
   "scripts": {
-    "dev": "react-scripts start",
+    "dev": "react-app-rewired start",
     "build": "react-scripts build",
     "test": "react-scripts test",
     "eject": "react-scripts eject",
@@ -13,6 +13,7 @@
     "@playwright/test": "^1.22.2",
     "@types/react": "^18.2.28",
     "@types/react-dom": "^18.2.13",
+    "react-app-rewired": "^2.2.1",
     "typescript": "^4.0.5"
   },
   "description": "[Azure Static Web Apps](https://docs.microsoft.com/azure/static-web-apps/overview) allows you to easily build JavaScript apps in minutes. Use this repo with the [quickstart](https://docs.microsoft.com/azure/static-web-apps/getting-started?tabs=vanilla-javascript) to build and customize a new static site.",

There seems to be an unrelated issue with SharedArrayBuffer not being defined due to missing COOP/COEP headers, but that can likely be fixed just by adjusting the Webpack config.

Since this isn't a problem with fflate, I'll close this issue for now. Let me know if you have any other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants