react-loosely-lazy icon indicating copy to clipboard operation
react-loosely-lazy copied to clipboard

Strip query strings from imports when resolving

Open marcins opened this issue 2 years ago • 1 comments

In some cases imports will contain query strings. The enhanced-resolver plugin for the "exports" field in package.json will fail to resolve these imports correctly. This change will strip any query strings from the import before resolving it.

The actual use case for this is that with Parcel we have created a set of plugins that will support Webpack's "magic comments" for naming async chunks. The way this plugin works is taking the chunk name and appending it to the import, e.g. import('@some/pkg?webpackChunkName=some-pkg' so it can later be accessed by a namer plugin.

RLL will fail on these imports in the rare case that the package contains an exports field, as the full string will be used to match so the query string will break things.

Added a new failing test for this - note as per the comment I was unable to get it working as a "fixture" because it doesn't appear fixtures are processed as modules, so the exports field wouldn't get used.

marcins avatar Aug 22 '22 01:08 marcins

So it turns out that removing query params in just the babel-plugin causes issues when attempting to do manifest lookups as the query param will still be present inside the module graph.

I've now updated the PR to strip query params in all places we reference a specifier/request.

mattcompiles avatar Oct 21 '22 03:10 mattcompiles