R159 + Vite, ModelNode.js:26 Uncaught TypeError: nodeImmutable(...).label(...).temp is not a function

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:

This line should be imported first:

1 Like

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' );

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.

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