three.js: Nodes: Nodes system throws exceptions when used with vite, `functionNode.call is not a function`
Description
I’m trying to use the Nodes system, including the MaterialX nodes, from a vite project.
Local development (unbundled) works fine, but bundling leads to errors. I was able to isolate and reproduce the issue, but I’m so far not sure if this is a three.js issue (some incorrect setup on the nodes) vs. a vite issue (something going wrong with bundling), or a combination thereof.
Reproduction steps
- Go to https://stackblitz.com/edit/vitejs-vite-9b37bu
- This roughly uses the code from https://threejs.org/examples/?q=materialx#webgl_nodes_materialx_noise
- There’s no attempt to output something visually, it’s just about getting things to run at all.
- Open the browser console
- Run
npm run start - Note no errors (code runs fine)
- Cancel the run by pressing Ctrl + C in the terminal
- Run
npm run previewwhich builds the code and hosts the resulting bundled code - In the console, note errors:
and when names are kept during bundling, and code is not minified:
I was able to track this down to FunctionNodes:
and
functionNode.call being undefined in a production build vs. in local development, but I’m not sure what may be causing this.
I’m not aware of a workaround for how to use the nodes/MaterialX system with a bundler at the moment.
Live example
Screenshots
No response
Version
r159
Device
Desktop, Mobile
Browser
Chrome, Safari
OS
Windows, MacOS
About this issue
- Original URL
- State: open
- Created 7 months ago
- Comments: 16 (11 by maintainers)
From https://github.com/mrdoob/three.js/pull/27189#issuecomment-1854016611:
From https://github.com/vitejs/vite/issues/15319#issuecomment-1855666500:
I’ll need to test globbing
./examples/jsm/nodes/*with Vite specifically, but best if we can avoid this altogether as per the first quote.A relatively simple way to access the project you provided at
https://stackblitz.com/edit/vitejs-vite-9b37bu, and then follow the steps below.I think that many of these problems were due to https://github.com/mrdoob/three.js/pull/25074, I was hoping to find an alternative solution, but it seems that the best option would be that the
method chainingonly works forOperatorNode,MathNode,ShaderNodethat would be the most used.Hasn’t this been solved in #27189?