JedWatson / JedWatson/react-select

Module augmentation not working with moduleResolution: bundler

Open
#5,743 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

There seems to be an issue with module augmentation and the exports field in package.json added in https://github.com/JedWatson/react-select/pull/5559 and improved in https://github.com/JedWatson/react-select/pull/5626. Module augmentation as described at https://react-select.com/typescript#custom-select-props appears to no longer work since react-select/dist/declarations/src/Select appears to no longer be the path of the Select module when the exports field in package.json is used during module resolution. I was unfortunately not able to figure out what the new path is. Deleting the exports field from package.json fixes the issue and module augmentation works as expected again.

The relevant section of building with tsc's traceResolution option enabled:

Failing with exports field being present

======== Resolving module 'react-select/dist/declarations/src/Select' from '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/types/module-augmentation.d.ts'. ========
Explicitly specified module resolution kind: 'Bundler'.
Resolving in CJS mode with conditions 'import', 'types'.
File '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/types/package.json' does not exist according to earlier cached lookups.
File '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/package.json' does not exist according to earlier cached lookups.
File '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/package.json' exists according to earlier cached lookups.
Loading module 'react-select/dist/declarations/src/Select' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/types/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/node_modules' does not exist, skipping all lookups in it.
File '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/package.json' exists according to earlier cached lookups.
Export specifier './dist/declarations/src/Select' does not exist in package.json scope at path '/Users/fabian/projects/brmlabs/brm/node_modules/react-select'.
Directory '/Users/fabian/projects/brmlabs/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/types/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/node_modules' does not exist, skipping all lookups in it.
File '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/package.json' exists according to earlier cached lookups.
Export specifier './dist/declarations/src/Select' does not exist in package.json scope at path '/Users/fabian/projects/brmlabs/brm/node_modules/react-select'.
Directory '/Users/fabian/projects/brmlabs/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'react-select/dist/declarations/src/Select' was not resolved. ========

Succeeding with exports field being deleted from react-select's package.json:

Resolving in CJS mode with conditions 'import', 'types'.
File '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/types/package.json' does not exist according to earlier cached lookups.
File '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/package.json' does not exist according to earlier cached lookups.
File '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/package.json' exists according to earlier cached lookups.
Loading module 'react-select/dist/declarations/src/Select' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/types/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/dist/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/fabian/projects/brmlabs/brm/node_modules/chakra-react-select/node_modules' does not exist, skipping all lookups in it.
File '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/package.json' exists according to earlier cached lookups.
File '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/dist/declarations/src/Select.ts' does not exist.
File '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/dist/declarations/src/Select.tsx' does not exist.
File '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/dist/declarations/src/Select.d.ts' exists - use it as a name resolution result.
Resolving real path for '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/dist/declarations/src/Select.d.ts', result '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/dist/declarations/src/Select.d.ts'.
======== Module name 'react-select/dist/declarations/src/Select' was successfully resolved to '/Users/fabian/projects/brmlabs/brm/node_modules/react-select/dist/declarations/src/Select.d.ts' with Package ID 'react-select/dist/declarations/src/Select.d.ts@5.7.4'. ========

Seems like the root cause is ./dist/declarations/src/Select' missing from the exports map:

Export specifier './dist/declarations/src/Select' does not exist in package.json scope at path '/Users/fabian/projects/brmlabs/brm/node_modules/react-select'.

Contributor guide

Open the 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.

Research direction

Inspect react-select's package.json exports map and the module-augmentation.d.ts entry point shown in the traceResolution output. Reproduce with TypeScript's moduleResolution: bundler and traceResolution enabled; done means the documented module augmentation resolves without deleting the exports field.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.