vagran / dxf-viewer

DXF 2D viewer written in JavaScript
Mozilla Public License 2.0
296 stars 87 forks source link

Cannot find namespace 'THREE' error, when using with Angular 16. #110

Open VadimKhismatov opened 1 month ago

VadimKhismatov commented 1 month ago

Hello. I am trying to implement dxf-viewer to my project on Angular 16. But I have error when building my project Cannot find namespace 'THREE'. All i did is installed packages dxf-viewer and three.js, added imports to component and run project with ng serve command, after that received several errors like this:

Error: node_modules/dxf-viewer/src/index.d.ts:21:17 - error TS2503: Cannot find namespace 'THREE'. 21 clearColor: THREE.Color,

My imports: import * as THREE from 'three'; import { DxfViewer } from "dxf-viewer";

This is stackblitz example with same errors.

How to fix this error?

vagran commented 1 month ago

It seems that the problem is that src/index.d.ts does not import three.js. It worked for me, but probably it depends on bundler/compiler. I am not really aware, if TS types declaration file should import something.

igortheodoro commented 1 month ago

Did you manage to solve this? I'm having the same issue here.

VadimKhismatov commented 1 month ago

Hello. I cloned package and added it to my project in root level of src folder src/dxf-viewer, after this added import * as THREE from 'three'; to dxf-viewer/src/index.d.ts file. In my component I import lib as always import { DxfViewer } from "src/dxf-viewer";but with path to my copy, not to node_modules. It seems to work for now, but if add worker like in example it still has same error for other declarations for DOM elements and other. May be if to make a build and add it to project, will be no errors, but in this case, all typing will be lost.