Replies: 13 comments 10 replies
-
This is weird, we do have tests running with nodejs in our CI: manifold/.github/workflows/manifold.yml Line 132 in dca9cce What is the version for your nodejs? |
Beta Was this translation helpful? Give feedback.
-
Thank you for your quick reply. I'm on And to help debug this, I've created a test repo https://github.com/frading/manifold-3d-test, where all I've done is:
And in this test, the error I get is different: So webpack and vite both try and import it differently. I'll keep investigate to try and see how I can tweak those configs, but curious to hear what you think in the mean time. Another suggestion that comes to mind, is that it would help import it if it was possible to give the url where to load the .wasm from to the |
Beta Was this translation helpful? Give feedback.
-
OK I think I misunderstood the problem. From emscripten documentation, it seems that you can modify the compiler args to build it for the web (https://emscripten.org/docs/getting_started/FAQ.html#can-i-build-javascript-that-only-runs-on-the-web) and bundle it as a single file which hopefully makes it easier for webpack/vite to work with (https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing) |
Beta Was this translation helpful? Give feedback.
-
ah, I did not realise the current .wasm was only for node. Ok, thanks a lot for those links, I'll give that a go and report back. |
Beta Was this translation helpful? Give feedback.
-
It should not be just for node, but I have not used frontend tools for a while and have no idea why it does not work with webpack. Please let us know your results, and if this works we can add it to the README. |
Beta Was this translation helpful? Give feedback.
-
Our npm library definitely works in the browser, simply look at manifoldcad.org, which uses it this way. From the file you link, the strangest part to me is that you await the module import and setup the WASM inside the |
Beta Was this translation helpful? Give feedback.
-
Yes, you're totally right, what I linked to is just a preliminary test to try and load your library. Once I got that working, it'll be cached. But for now, my attempts to load it, in both repos I've linked, using webpack or vite, have failed. And unless I'm missing something obvious, I'm doing it the same way as the file you just pointed to. |
Beta Was this translation helpful? Give feedback.
-
@frading That is odd - I'm not familiar with webpack or vite; have you tried with vanilla JS? I wonder if they need some configuration for ES6 modules? |
Beta Was this translation helpful? Give feedback.
-
Hi @frading, I'm successfully using Manifold with Vite in a SvelteKit project. You just need to point the import Module from 'manifold-3d';
import manifold_wasm from 'manifold-3d/manifold.wasm?url';
const manifold_module = await Module({
locateFile: () => manifold_wasm,
});
manifold_module.setup(); The See Manifold running in an example Svelte project using Vite at https://stackblitz.com/edit/manifold-vite?file=src%2FApp.svelte&terminal=dev If you use TypeScript, it will complain that the So, currently, Manifold npm package is not usable without this extra knowledge with Vite (and Webpack). I don't know yet how this should be done properly. I'll try to find some other package that is also using wasm and is working out-of-the-box with Vite, for inspiration. But definitely, a least the TypeScript definitions could be fixed easily, so it's clear for the TypeScript users there is the |
Beta Was this translation helpful? Give feedback.
-
It seems that npm packages using wasm modules encouters the exact same problem. And providing the URL to the wasm file to the module load function is the best option. For example, here is a relevant documentation for OpenCascade.js: Configuring Your Bundler. |
Beta Was this translation helpful? Give feedback.
-
ok, I could make some progress here. I now have a version that's working in polygon, but it has a few caveats that I describe below. And @jirihon thanks a lot for your suggestion for vite. Using The 2 remaining problems are:
There are other similar lines that are only for node, such as
So the solution I currently have is to copy the files from the And that solution works for me at the moment, although I'm not sure if that does comply with manifold's license. It would be good if you could confirm if it does, in which case I'll happily proceed like this. If not, I'd love to hear suggestions on how to improve the webpack config, if possible, as @jirihon message marked as a solution is a vite-only solution. |
Beta Was this translation helpful? Give feedback.
-
I used the 'workaround' changes that @frading proposed in his latest comment to create an npm package that should be compatible with webpack, for use in the browser. This is just to save other people that are using webpack some headache, for the time being. |
Beta Was this translation helpful? Give feedback.
-
Came across the same issues with webpack so here's what worked for me.
ymmv, since create react app setup has a bunch of other configurations. |
Beta Was this translation helpful? Give feedback.
-
Hello,
As I mentioned in the Users of Manifold discussion, I'm starting to integrate Manifold in Polygonjs. But I'm quickly facing issues, as importing the library generates the following error:
It seems to come from
await import('module')
insidenode_modules/manifold-3d/manifold.js
. So I can temporarily work around it by removing the whole block insideif (ENVIRONMENT_IS_NODE) {...}
. (as I'm building for the browser, not for node).Then the app builds, but loading the wasm file generates a second error:
And this is unfortunately not an error I'm able to debug.
So this brings me 2 questions:
1 - Would it be possible to have a build in the npm module that is only for the browser and does not include nodejs specific instructions? Alternatively, could you suggest modifications to my webpack config that could solve this?
2 - Is there anything I should change to load the .wasm without the error above?
This issue may need to be split into 2 for clarity, feel free to let me know if so, I'll happily do it.
You can see my attempt to integrate manifold in the integration-manifold branch of polygonjs, and specifically this file. You can also start it with
yarn && yarn start
and view any errors in the dev console when opening it onhttp://localhost:8080/example.html?id=nodes/sop/SDFBox
.Don't hesitate to let me know if you need more info from me
Beta Was this translation helpful? Give feedback.
All reactions