-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add exports
field in package.json
#5559
Add exports
field in package.json
#5559
Conversation
🦋 Changeset detectedLatest commit: c187990 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c187990:
|
@gdiazdelaserna Has this been tested with webpack and vite? |
I have tested this change in multiple environments. I created this repo to show how this has been tested: https://github.com/gdiazdelaserna/react-select-exports-field-test As you can see, I tested this in:
This proves that:
Here's a screenshot of the 4 apps running correctly: |
TL;DR
Fixes the issue mentioned here: #4859
Description
Issue
Consuming a React Select subpath from a JS module in a project using Webpack 5, throws an error saying the path in the import statement is not fully specified.
Context
Webpack 5 introduced a default behavior that requires all import statements in JS modules to be fully specified.
Importing a React Select subpath (e.g.
import Creatable from 'react-select/creatable'
) is breaking that rule. Webpack 5 thinks that import statement is trying to import a file with a missing extension.Solution
Inform Webpack that the subpaths are not file imports (and an extension shouldn't be required) by declaring an
exports
field inpackage.json
.The
exports
field is documented in these two places:The new
exports
field includes all the subpaths mentioned in React Select's documentation. All other subpath imports will fail from now on.Each subpath declared in the
exports
field includes 3 different file system paths to satisfy the different environments that might consume them:require
: Will be used by environments using therequire
keyword to import files (e.g CommonJS)import
: Will be used by environments using theimport
keyword to import files (e.g. ES Modules)types
: Will be used by TypeScript to query type definitions