Fix export support for webpack <5.94 #6033
Open
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
name: Pull Request
about: Create a pull request to improve this repository
title: Add export support for webpack <5.94
labels: ""
assignees: ""
Description
Linked issue: #(issue number)
5437
Problem
Attempting to import any
./dist/*.css fromfrom react-datepicker 8 will not work in Webpack <=5.93.In react-datepicker 8.0, the exports field was introduced to its package.json. While the expressions in the current export configuration are technically correct in principle, earlier versions of Webpack 5 (<5.94)have quirky behaviour when processing these patterns and combined with its stricter enforement of exports, results in import failures on valid paths.
Webpack's resolver only recently implemented pattern matching parity w/Node.js in Webpack 5.94:
While a simple upgrade of Webpack should solve this problem, this bug is amplified by the fact that many folks still use popular tools locked to older versions of Webpack. CRACO relies on react-scripts which is locked to Webpack 5.75 in perpetuity, as react-scripts is no longer maintained. Next.js >=12 is locked to Webpack 5.64 (as per the final Next.js 12 release). In both cases, overriding Webpack to use a later version isn't possible through conventional package.json override means. In the case of Next.js 12, Webpack is actually bundled into the distribution.
Changes
I've removed the *.css wildcard expression from file exports in package.json. Tested in Webpack 5.75. This does expose all of
./distto export, however.Screenshots
To reviewers
Alternatively, I thought of explicitly listing each css file in the package.json exports as the current solution will open all assets in
./distto exporting. Unsure if this is a problem for the maintainers of react-datepicker. The solution proposed in this PR seems easier to maintain if new css bundles are ever distributed.e.g.:
Contribution checklist