Below is the bit of the code which sets the texture and maps it onto a large sphere. I have tried all sorts of wrapping but the background is still not smooth as there is a clear joining where the two parts of the texture meets. How do I fix this? Is there a way to overlap the edges maybe?
var milkyWayTexture = loader.load('https://cdn.pixabay.com/photo/2016/11/21/12/30/milky-way-1845068_1280.jpg');
milkyWayTexture.minFilter = THREE.LinearFilter;
milkyWayTexture.magFilter = THREE.LinearFilter;
milkyWayTexture.wrapS = THREE.RepeatWrapping;
milkyWayTexture.wrapT = THREE.RepeatWrapping;
// Create a large sphere mesh for the starry background
var backgroundGeometry = new THREE.SphereGeometry(900, 100, 100);
backgroundGeometry.scale(-1, 1, 1); // Flip the geometry to invert the texture mapping
var backgroundMaterial = new THREE.MeshBasicMaterial({
side: THREE.DoubleSide, // Make the sphere visible from inside as well as outside
map: milkyWayTexture // Add Milky Way texture
});
var backgroundMesh = new THREE.Mesh(backgroundGeometry, backgroundMaterial);
scene.add(backgroundMesh);

You need to understand the concept of UV mapping. It defines how your texture will be projected on a 3D object.
Usually, on a sphere, if you simplify the concept to its core, it consists of a plane rotate in X and Y, to wrap on a sphere.
With the illustration you might have guess the solution:
Equirectangularmapping of the milky way texture (example).360 panoramatexture of milky way (example).Alternatively, to set an environment I think it's a better practice to use
scene.background(source) with aEquirectangularReflectionMappingtexture from an HDR file (can be found here).