njam / citygml-to-3dtiles

Convert from CityGML to Cesium 3D Tiles.
Apache License 2.0
160 stars 41 forks source link

Error: require() of ES Module is not supported #25

Open pcace opened 1 year ago

pcace commented 1 year ago

Hi,

i am trying to get your library to run in nodejs, but i am stuck importing it correctly. is the problem on my side or is something broken with the library? this is the errormessage:

Error: require() of ES Module C:\Users\user\Documents\citygmlToGltf\node_modules\citygml-to-3dtiles\src\Converter.mjs not supported.
Instead change the require of C:\Users\user\Documents\citygmlToGltf\node_modules\citygml-to-3dtiles\src\Converter.mjs to a dynamic import() which is available in all CommonJS modules.       

when having this in my app.ts:

import Converter from "citygml-to-3dtiles";
  let converter = new Converter();

(i also had to add a citygml-to-3dtiles.d.ts in node-module/@types) and added "type" : "module", to the package.json of the module... with no luck

any idea what i am doing wrong here?

Thanks a lot!

njam commented 1 year ago

What's your NodeJS version? It seems you're using Typescript. Can you try without Typescript, does that work?

The error message suggests using dynamic import, have you tried that? I don't have experience with it, so can't suggest exact syntax.

pcace commented 1 year ago

hi, my Node.js is v16.14.2. i will give it a try, but i need to be in TS environment :/

njam commented 1 year ago

I'm not too knowledgeable about JS modules/import. But it looks to me like the module/file from which you import citygml-to-3dtiles from doesn't support the type of import you're using (the one from this repo's readme). I'd try the dynamic import instead.