Why I "import {If} from 'three/nodes'",its error ‘The requested module '/node_modules/.vite/deps/three_nodes.js?v=fdd2419d' does not provide an export named 'If'’

but at “https://github.com/mrdoob/three.js/blob/4527c3e8498ebdc42e7eb40fcfa90435b9c95514/examples/webgpu_compute_particles_rain.html”,it can success

my three version is latest?
who can help me? thanks!

The example you shared is using import maps which defines the directory required as three/nodes…

"imports": {
	"three": "../build/three.module.js",
	"three/addons/": "./jsm/",
	"three/nodes": "./jsm/nodes/Nodes.js"

To achieve the import in vite you would use the absolute path name eg…

1 Like

hah,The way you said, it did work out,Thanks!
but i have a question, node_modules/threejs packages.json have a field with exports: ‘“./nodes”: “./examples/jsm/nodes/Nodes.js”’,why i can’t use ‘three/nodes’,I don’t understand

:thinking: hmm good question it looks like it should work that way now you point that out… maybe someone will have some ideas why that doesn’t work in vite…

 "name": "three",
 "version": "0.158.0",
 "description": "JavaScript 3D library",
 "type": "module",
 "main": "./build/three.js",
 "module": "./build/three.module.js",
 "exports": {
   ".": {
     "import": "./build/three.module.js",
     "require": "./build/three.cjs"
   "./examples/fonts/*": "./examples/fonts/*",
   "./examples/jsm/*": "./examples/jsm/*",
   "./addons": "./examples/jsm/Addons.js",
   "./addons/*": "./examples/jsm/*",
   "./src/*": "./src/*",
   "./nodes": "./examples/jsm/nodes/Nodes.js"
 "repository": {
   "type": "git",
   "url": "https://github.com/mrdoob/three.js"
 "sideEffects": false,
 "files": [