So, I have a vite project where I use three. Unfortunately, I don’t use the official three.js npm package, but rather ought to use a fork which has some changes suited for my project’s needs.
This fork sits locally on my machine, and I use yarn link
to link the fork to my project. Everything was fine up until r136
(well, my slightly modified version of r136
), but when I updated my fork to r137
things broke down, and they’ve broken down because of the change regarding import maps introduced in r137
.
I’ve added in my vite.config.js
file the following:
import alias from '@rollup/plugin-alias';
...
plugins:[
alias({
entries: [
{
find: 'three',
replacement: resolve(__dirname, 'node_modules/three/build/three.module.js'),
},
],
}),
]
This resolved all imports of the form import {Something} from "three"
made in my project.
But imports of this from made in three’s example folder aren’t resolved. For example, the import from “three” in OutlinePass.js
:
import {
AdditiveBlending,
Color,
DoubleSide,
LinearFilter,
Matrix4,
MeshDepthMaterial,
NoBlending,
RGBADepthPacking,
RGBAFormat,
ShaderMaterial,
UniformsUtils,
Vector2,
Vector3,
WebGLRenderTarget
} from 'three';
import { Pass, FullScreenQuad } from './Pass.js';
import { CopyShader } from '../shaders/CopyShader.js';
installing the official r137
from the npm registry doesn’t give me any problems.
I emphasize that none of the modifications made in my fork aren’t related to the build flow, or modules structure or anything like that.
I don’t know if it’s a general vite thing I’m missing, or something specific to the way the three package is included in the project via yarn link
, and I realize it’s not exactly a three.js specific thing. Regardless I would apperciaite the help very much.