-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Describe the bug
In short: I'm looking for a way to bundle OpenCV.js in my SvelteKit project (which utilizes Vite). It's not clear to me if it's OpenCV.js's issue, or something on the Vite end, but I've exhausted all my resources in trying to figure out the issue described below. Any help would be much appreciated!
Less short:
OpenCV produces a javascript version of their plugin: OpenCV.js
Taking a look at the source, it seems like the authors must've intended the plugin to work nicely in both node and browser. Unfortunately, it seems some of their attempts to make the library flexible have caused trouble when including it in a project bundled/built by Vite.
I'm specifically trying to use an npm pacakge that simply wraps the source, @techstark/opencv-js (NOTE: Other similar packages exist, which have similiar issues).
Without any changes to the default SvelteKit / Vite config, the project builds with no errors but cannot be loaded (i.e. If i navigate to the port, the browser endlessly hangs).
If I fight with the config enough (mainly using resolve.alias to handle issues of the opencv.js 'requiring' "fs", "path", and "crypto"), I can get the page to load, but it will throw an Uncaught ReferenceError: Module is not defined error, as can be seen in the Reproduction below.
It seems the prevailing wisdom and assumption is that, if OpenCV.js is going to be bundled, it needs to be done so with Webpack (this is what @techstark/opencv-js's author recommends, and what I have personal success doing). I'm hoping that that won't have to be the case, so I can happily bundle OpenCV.js in with my SvelteKit projects.
Thank you!
Reproduction
https://stackblitz.com/edit/vitejs-vite-ijha1v?file=main.js
System Info
System:
OS: macOS 11.6
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 435.54 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.13.2 - ~/project-path/local-node-install/node/bin/node
Yarn: 1.22.17 - ~/npm/bin/yarn
npm: 8.1.2 - ~/project-path/local-node-install/node/bin/npm
Browsers:
Chrome: 97.0.4692.99
Firefox: 96.0.3
Safari: 14.1.2Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.