Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package causes "Multiple instances" three.js warning #6

Open
wuhhh opened this issue Jan 24, 2023 · 9 comments
Open

Package causes "Multiple instances" three.js warning #6

wuhhh opened this issue Jan 24, 2023 · 9 comments

Comments

@wuhhh
Copy link

wuhhh commented Jan 24, 2023

I am seeing the WARNING: Multiple instances of Three.js being imported. message in console. I narrowed it down to this dependency. If I remove the component which uses it, the warning goes away. I am on 1.1.7.

Package.json deps :

"dependencies": {
    "@react-three/csg": "^1.1.7",
    "@react-three/drei": "^9.32.3",
    "@react-three/fiber": "^8.8.7",
    "lamina": "^1.1.23",
    "leva": "^0.9.34",
    "r3f-perf": "6.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "^5.0.1",
    "three": "^0.145.0",
    "three-stdlib": "^2.20.3",
    "zustand": "4.0"
  },
@drcmda
Copy link
Member

drcmda commented Jan 24, 2023

can you move to 2.x? i don't see the warning.

@wuhhh
Copy link
Author

wuhhh commented Jan 26, 2023

I tried it with the same result on 2.0.7.

I used some of the sample code from your docs:

<mesh>
	<meshNormalMaterial />
	<Geometry>
		<Base scale={[2, 0.5, 0.5]}>
			<boxGeometry />
		</Base>
		<Addition>
			<boxGeometry scale={[1, 0.5, 0.5]} />
		</Addition>
	</Geometry>
</mesh>

If I remove the above chunk, the error goes away.

@wuhhh
Copy link
Author

wuhhh commented Jan 26, 2023

I installed the house sandbox locally - same error here in Chrome incognito window, I don't see the warning in Firefox

Screenshot 2023-01-26 at 14 54 58

@drcmda
Copy link
Member

drcmda commented Jan 26, 2023

then it must be the base library three-bvh-csg, will investigate

edit: nope, loops good, three is marked a peerDependency

no idea from where it comes from tbh. this library's only dependency is bvh-csg.

@drcmda
Copy link
Member

drcmda commented Jan 26, 2023

when i download the house demo by clicking the csb dl button, yarn it, yarn start, i don't see any warnings in chrome.

@wuhhh
Copy link
Author

wuhhh commented Jan 26, 2023

Then I think this issue is something to do with using npm - because I just tried with yarn and you're right, there's no such warning. I was on npm 8.3.1 so I just updated to 8.19.3 and the warning is still there.

@chrislicodes
Copy link

Any news on this @wuhhh? I also encounter the same problem now.

@levivoelz
Copy link

levivoelz commented May 15, 2023

I have the same issue. Switching to yarn didn't help (yarn v3). Here's an output from yarn install:

➤ YN0000: ┌ Resolution step
➤ YN0002: │ @react-three/csg@npm:2.2.0 doesn't provide three (p9aa34), requested by three-bvh-csg
➤ YN0002: │ @react-three/csg@npm:2.2.0 doesn't provide three-mesh-bvh (pd06b0), requested by three-bvh-csg
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 0s 468ms

Normally, I'd just ignore the peer dependency warning, but there are multiple instances of three being installed and bundled—specifically 0.141.0 which is what three-bvh-csg wants as a peer dependency and 0.152.0 which is a dependency in my project.

Now, switching back to npm (v9.5.1) I can see that [email protected] is installed in @react-three/csg/node_modules. I think this has to do with peerDependencies being installed by default for sub-packages. I think for three to not be installed here it needs to be set as a peerDependency in this package. I found this article about it: https://dev.to/arcanis/implicit-transitive-peer-dependencies-ed0

Screen Shot 2023-05-14 at 5 47 47 PM

@levivoelz
Copy link

I was able to fix this by adding "three": ">=0.141.0" as a peer dependency to this package and by changing the peer dependency in three-bvh-csg from "three": "^0.141.0" to "three": ">=0.141.0". I can submit a PR if y'all want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants