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

Open
#342 4 comments 3 reactions 0 assignees View on GitHub

A pull request for this has already been merged.

  • #343 by @CodyJasonBennett — merged

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
three.js, typescript
Domain
tooling

Research direction

Start by reproducing the reported import from src/Scene.tsx with the NodeNext settings in tsconfig.json and run TSC. Compare the package's exported types with the behavior under NodeNext module resolution. Done means GLTF and GLTFLoader compile as exported members without requiring the ESNext/Node workaround.

Written by the indexing model from the issue text.

Description

bug released
  • 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.

Dominant language
JavaScript
Stars
863
Forks
146
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pmndrs/three-stdlib

All issues in pmndrs/three-stdlib

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.