three.js: Circular dependency in ShaderNode
Description
ShaderNode.js:3 Uncaught (in promise) ReferenceError: Cannot access 'ShaderNode' before initialization
at Object.ShaderNode (ShaderNode.js:3:59)
at eval (SkinningNode.js:8:87)
at ./node_modules/three/examples/jsm/nodes/accessors/SkinningNode.js (chunk.vendors-node_modules_blueimp-md5_js_md5_js-node_modules_element-resize-detector_src_element-r-f0dec0.bfeca9936d49aeae8903.js:2501:1)
at __webpack_require__ (chunk.app.0c10a065d695b4093c2e.js:107:42)
at eval (ShaderNodeElements.js:248:85)
at ./node_modules/three/examples/jsm/nodes/shadernode/ShaderNodeElements.js (chunk.vendors-node_modules_blueimp-md5_js_md5_js-node_modules_element-resize-detector_src_element-r-f0dec0.bfeca9936d49aeae8903.js:3590:1)
at __webpack_require__ (chunk.app.0c10a065d695b4093c2e.js:107:42)
at eval (ShaderNode.js:20:80)
at ./node_modules/three/examples/jsm/nodes/shadernode/ShaderNode.js (chunk.vendors-node_modules_blueimp-md5_js_md5_js-node_modules_element-resize-detector_src_element-r-f0dec0.bfeca9936d49aeae8903.js:3568:1)
at __webpack_require__ (chunk.app.0c10a065d695b4093c2e.js:107:42)
Reproduction steps
use NodeMaterial and build with webpack
Code
// code goes here
Live example
n/a
Screenshots
No response
Version
158
Device
Desktop
Browser
Chrome
OS
Windows
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 30 (21 by maintainers)
I think the issue is that
ShaderNodeis exported two times,one here
https://github.com/mrdoob/three.js/blob/5f75a1bddf43237e150be0f7195cf5e87a4b0f92/examples/jsm/nodes/shadernode/ShaderNode.js#L203
and one here
https://github.com/mrdoob/three.js/blob/5f75a1bddf43237e150be0f7195cf5e87a4b0f92/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js#L59
For this it’s causing the circular dependency when imported inside
SkinningNode.jshttps://github.com/mrdoob/three.js/blob/5f75a1bddf43237e150be0f7195cf5e87a4b0f92/examples/jsm/nodes/accessors/SkinningNode.js#L2-L16
Hmm… Better remove it from
ShaderNodeBaseElementI think.Finally finished it: https://github.com/mrdoob/three.js/pull/25498
Mostly finished the PR, will test and file it tomorrow.
Actually, there is a problem here that such syntax is import-order-dependent – so with it, to properly use the chaining syntax in “core” nodes we need to maintain a proper import order in Nodes.js (maybe just math classes first). But it’s doable…
Started working on it, will file a PR soon.
So that something like
node.negate().add( otherNode ).functionThatUserAdds( thirdNode )works.@LeviPesin Ah yeah! I think so.
More detail for the update:
In
examples/jsm/nodesthe tools say there are 22 circular dependencies.Using madge 5.02 (latest has a bug and wont generate graphs) Update: latest is fixed.
From the
examples/jsm/folder run the following command. Thewarningflag at the end displays files it skipped if any.This gives the following output on the current dev branch:
Graph of just the circular dependency issues:
The complete graph:
red = circular dep blue = normal, with deps green = leaf node, no deps
It works in browser. So it is rather a Webpack bug…