CesiumGS / obj2gltf

Convert OBJ assets to glTF
Apache License 2.0
1.68k stars 303 forks source link

(node:35442) Warning: require() of ES modules is not supported. #225

Closed aaronxowen closed 4 years ago

aaronxowen commented 4 years ago

I am trying to convert an obj that doesn't reference an mtl to GLB using PBR textures explicitly set by the option flags using the following command:

obj2gltf -i Monaco1-DrawerNightstand_82334_low_scaled.obj -o Monaco1-DrawerNightstand_82334_ClassicPaint_CoastalClear_PolishedNickel.glb -b --baseColorTexture Monaco1-DrawerNightstand_82334_ClassicPaint_CoastalClear_PolishedNickel_Albedo.jpg --normalTexture Monaco1-DrawerNightstand_82334_ClassicPaint_CoastalClear_PolishedNickel_Normal_OpenGL.png --metallicRoughnessOcclusionTexture Monaco1-DrawerNightstand_82334_ClassicPaint_CoastalClear_PolishedNickel_MetallicRoughnessOcclusionRGB.jpg

When run, I get this: (node:35442) Warning: require() of ES modules is not supported. require() of /usr/local/lib/node_modules/obj2gltf/node_modules/cesium/index.js from /usr/local/lib/node_modules/obj2gltf/bin/obj2gltf.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/local/lib/node_modules/obj2gltf/node_modules/cesium/package.json. ENOENT: no such file or directory, open '/Users/aaron/Desktop/GLTF_tests/iOS_Optimized/Monaco1-DrawerNightstand_82334_low_scaled.obj'

A GLB file is output, but doesn't seem to have the correct maps in place.

lilleyse commented 4 years ago

@aaronxowen CesiumJS was recently updated to ES6 so it's possible that's related to the warning. A few questions...

I'm not seeing any issues on my end after updating packages but there could be a few different factors at play.

aaronxowen commented 4 years ago

Originally I tried to use 13.2.0, but couldn't get it to run at all on the command line (macOS 10.14.6), so I switched to node 12.13.1 and it runs, but with those errors.

I believe that the "ENOENT: no such file or directory" error is related to the .obj not referencing a mtl at all. I had exported the obj from Maya with materials turned off, so there were no "usemtl" or "mtllib" statements in the obj. I thought I'd be able to override the lack of mtl with specific mappings to external texture files like I do with Apple's python USDZ converter.

If I run obj2gltf on an obj that references a mtl file and override with the flags for external texture map files, it appears to work correctly, but still throws the warning about require():

(node:51774) Warning: require() of ES modules is not supported. require() of /usr/local/lib/node_modules/obj2gltf/node_modules/cesium/index.js from /usr/local/lib/node_modules/obj2gltf/bin/obj2gltf.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/local/lib/node_modules/obj2gltf/node_modules/cesium/package.json. Total: 1032.669ms

lilleyse commented 4 years ago

@aaronxowen we're tracking this from the cesium side - https://github.com/AnalyticalGraphicsInc/cesium/issues/8452

We hope to have a fix by the next Cesium release on Jan 2.

lilleyse commented 4 years ago

CesiumJS 1.68.0 was released yesterday with the fix. I tested that obj2gltf now works with Node 13.12.0.