Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module augmentation not working with moduleResolution: bundler #5743

Open
FabianFrank opened this issue Sep 1, 2023 · 1 comment
Open

Module augmentation not working with moduleResolution: bundler #5743

FabianFrank opened this issue Sep 1, 2023 · 1 comment
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet

Comments

@FabianFrank
Copy link

FabianFrank commented Sep 1, 2023

There seems to be an issue with module augmentation and the exports field in package.json added in #5559 and improved in #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'.
@csandman
Copy link

csandman commented Sep 29, 2023

I am running into this issue as well on my wrapper for this package chakra-react-select. I'm not sure this has anything to do with the change in #5626 though, as I'm having the same issue after reverting to v5.7.2. I'm really not too familiar with the inner workings of module augmentation, is there something that changed with it when using moduleResolution: "bundler"?

I'm also having the issue with node16/nodenext.

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet
Projects
None yet
2 participants