0b5vr
December 5, 2023, 9:30am
1
It seems that Vite’s code chunking swaps modules with side effects and making the code unfunctional.
It occurs when I simply import "three/nodes".
The chunk runs ModelNode before the VarNode which is not good.
I don’t know what is the exact condition to reproduce this issue.
I don’t know what to do, but I’m leaving this as a despair scream.
I will probably stay away from Vite and go importmap instead like Three.js examples do for now.
This is the line where the error occurs:
super.update( frame );
}
}
export default ModelNode;
export const modelDirection = nodeImmutable( ModelNode, ModelNode.DIRECTION );
export const modelViewMatrix = nodeImmutable( ModelNode, ModelNode.VIEW_MATRIX ).label( 'modelViewMatrix' ).temp( 'ModelViewMatrix' );
export const modelNormalMatrix = nodeImmutable( ModelNode, ModelNode.NORMAL_MATRIX );
export const modelWorldMatrix = nodeImmutable( ModelNode, ModelNode.WORLD_MATRIX );
export const modelPosition = nodeImmutable( ModelNode, ModelNode.POSITION );
export const modelScale = nodeImmutable( ModelNode, ModelNode.SCALE );
export const modelViewPosition = nodeImmutable( ModelNode, ModelNode.VIEW_POSITION );
addNodeClass( 'ModelNode', ModelNode );
This line should be imported first:
return propertyName;
}
}
export default VarNode;
export const temp = nodeProxy( VarNode );
addNodeElement( 'temp', temp ); // @TODO: Will be removed in the future
addNodeElement( 'toVar', ( ...params ) => temp( ...params ).append() );
addNodeClass( 'VarNode', VarNode );
1 Like
sunag
December 7, 2023, 2:39am
2
Hi @0b5vr . Have you tried removing the label()? It seems unnecessary in this section, I think I forgot to remove it.
export const modelViewMatrix = nodeImmutable( ModelNode, ModelNode.VIEW_MATRIX ).temp( 'ModelViewMatrix' );
0b5vr
December 7, 2023, 8:33am
3
I just tried using a self-built Three.js r159 (linked via pnpm link), and replacing itself fixed the problem. Very bizarre behavior…
Removing the label() didn’t change the behavior.
0b5vr
December 7, 2023, 9:14am
4
I resolved this using Vite config’s optimizeDeps.exclude !
// ...
optimizeDeps: {
exclude: [
'three', // to prevent Vite's code chunking which causes an error
],
esbuildOptions: {
target: 'esnext', // Three.js uses top-level await
},
},
// ...
1 Like