three-stdlib icon indicating copy to clipboard operation
three-stdlib copied to clipboard

"no exported member" errors when using NodeNext module/moduleResolution in TypeScript

Open bhouston opened this issue 1 year ago • 4 comments

  • three version: n/a
  • @types/three version: n/a
  • three-stdlib version: 2.29.4

Problem description:

I ran into this bug and it took a while to figure out. It turns out that this library (as well as threes-stdlib) are not compatible with "NodeNext" module/moduleResolution, e.g. if you tsconfig.json looks like this:

    "module": "NodeNext",
    "moduleResolution": "NodeNext",

And you try to use this library like this:

Code:

import { GLTF, GLTFLoader } from 'three-stdlib'

You will get compile errors via TSC like this:

src/Scene.tsx:17:16 - error TS2305: Module '"three-stdlib"' has no exported member 'GLTFLoader'.

You can work around the bug by switching your tsconfig.json to something like this instead:

    "module": "ESNext",
    "moduleResolution": "Node",

Relevant code:

Included in the above description.

Suggested solution:

I suspect there is some way to fix this? But I do not yet know. One clue is that @react-three/fiber and @react-three.drei work properly with these tsconfig.json settings.

bhouston avatar Jan 23 '24 01:01 bhouston

Yes, this is bizarre. I just switched to nodenext because https://github.com/sindresorhus/meow required it for a similar reason as mentioned here https://github.com/sindresorhus/meow/issues/248#issuecomment-1793680332

That links to a related babylon issue https://github.com/BabylonJS/Babylon.js/issues/13797

It looks like it could be spec required file extension.

@bhouston how did you end up working around it?

rosskevin avatar Jan 19 '25 00:01 rosskevin

:tada: This issue has been resolved in version 2.35.8 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jan 19 '25 02:01 github-actions[bot]

It looks like it could be spec required file extension.

That is the issue here, in addition to needing the same treatment with .d.cts for CommonJS.

CodyJasonBennett avatar Jan 19 '25 02:01 CodyJasonBennett

Had to revert. We're not given the tools necessary to meet these conditions without directly extending the TypeScript compiler. I do plan to deprecate this package as soon as three accepts any upstream contributions here, and they then require ESM for WebGPU (top-level await). Until then, this library effectively serves as a CJS build for three/addons.

CodyJasonBennett avatar Jan 19 '25 20:01 CodyJasonBennett