Skip to content

Vite: Multiple instances of Three.js being imported #3601

@busticated

Description

@busticated

hey there 👋

i'm trying to track down why i'm seeing the Multiple instances of Three.js being imported. warning in my tests here. i've reviewed a number of seemingly related issues over in mrdoob/three.js - most notably this - but have not been able to get things fixed.

the issue appeared after we added and started using @react-three/test-renderer. it only happens in our tests.

when i look at my deps, i see:

>>npm ls --depth 0
[email protected] /Users/me/code/my-app
├── @eslint/[email protected]
├── @react-three/[email protected]
├── @react-three/[email protected]
├── @react-three/[email protected]
├── @stylistic/[email protected]
├── @testing-library/[email protected]
├── @testing-library/[email protected]
├── @testing-library/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @vitejs/[email protected]
├── @vitest/[email protected]
├── @vitest/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

scanning for three specifically:

>>npm ls three              
[email protected] /Users/me/code/my-app
├─┬ @react-three/[email protected]
│ ├─┬ @monogrid/[email protected]
│ │ └── [email protected] deduped
│ ├─┬ @react-spring/[email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├── [email protected] deduped
│ └─┬ [email protected]
│   ├── [email protected] deduped
│   └─┬ [email protected]
│     └── [email protected] deduped
├─┬ @react-three/[email protected]
│ └── [email protected] deduped
├─┬ @react-three/[email protected]
│ └── [email protected] deduped
└── [email protected]

my vite config is a bit complex but i did try adding:

  resolve: {
    alias: {
       'three/examples/jsm': 'three/examples/jsm',
       'three/addons': 'three/examples/jsm',
       'three/tsl': 'three/webgpu',
       'three': 'three/webgpu',
    }
  }

...but it didn't suppress the warning.

collecting my import statements - as i understand certain patterns here can trigger the warning - i see:

// three (Core Library)
import * as THREE from 'three';
import type * as THREE from 'three';
import { Color } from 'three';
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js';

// @react-three/fiber
import { Canvas, useThree } from '@react-three/fiber';
import { useThree, type ThreeEvent } from '@react-three/fiber';
import { useFrame, useThree } from '@react-three/fiber';
import { Canvas } from '@react-three/fiber';
import { useThree } from '@react-three/fiber';

// @react-three/drei
import { OrbitControls, PerspectiveCamera, OrthographicCamera } from '@react-three/drei';
import { Line } from '@react-three/drei';
import { OrbitControls } from '@react-three/drei';

// @react-three/test-renderer
import ReactThreeTestRenderer from '@react-three/test-renderer';

// three-stdlib
import type { OrbitControls } from 'three-stdlib';

all suggestions very much appreciated 🙏 👍

original report 👉 mrdoob/three.js#32142

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions