javascriptthree.jscsg

getting error "requested module './three-csg.js' does not provide an export named 'CSG' "


i am doing some simple CSG operations on cube and sphere.. for that, i am using three-csg.js library form "https://github.com/manthrax/THREE-CSGMesh" after giving operations I am getting error like " Uncaught SyntaxError: The requested module './three-csg.js' does not provide an export named 'CSG' "
coded as given below and also added the other two libraries as required(csg-lib.js, csg-lib.js)

import { CSG } from "./three-csg.js";

// -----------------------------------------------------(scene, camera, renderer are defined)

const cubegeometry = new THREE.BoxGeometry( 0.02, 0.02, 0.02 );
const cubematerial = new THREE.MeshBasicMaterial( {color: 0x00ff00,} );
const cube = new THREE.Mesh( cubegeometry, cubematerial );
const cubegeometry = new THREE.BoxGeometry( 0.02, 0.02, 0.02 );
const cubematerial = new THREE.MeshBasicMaterial( {color: 0x00ff00,} );
const cube = new THREE.Mesh( cubegeometry, cubematerial );
const cubeCSG   = CSG.fromMesh(cube);
const sphereCSG = CSG.fromMesh(sphere);
const resultCSG = cubeCSG.subtract(sphereCSG); 
const CSGmaterial = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const meshCSG = CSG.toMesh( resultCSG );
meshCSG.material = CSGmaterial;

scene.add( meshCSG );

Solution

  • Have you looked at the source code of the demos? All you need to do is remove the curly braces

    import CSG from "./three-csg.js";