You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Packages making use of the browser field in their package.json to replace certain imports with others when running in a browser context throw an error.
This is not an issue if the package defines esmodules, modern, module, ..., but occurs in the case of the axios package for example because they define only the browser and main in their package.json.
The issue also doesn't occur if the browser field is simply a string.
To Reproduce
(Add the axios package) and import it in any file
Run npm start (or yarn run start if that's more your cup of tea)
Navigate to the page and see the error
Expected behavior
WMR bundles the package and handles the browser field correctly.
Bug occurs with:
wmr or wmr start (development)
wmr build (production)
wmr serve
Desktop (please complete the following information):
resolve.exports's legacy (imported as _resolveLegacyEntry in this file) can also return a Record<string, string | false> due to the browser field, which is not handled - the code tries to call replace on what is possibly an object, causing it to throw an error in cases like these.
The text was updated successfully, but these errors were encountered:
Aeriit
changed the title
WMR does not handle the "browser" field of packages correctly
WMR does not handle the "browser" field of imported packages correctly
Jul 27, 2021
Describe the bug
Packages making use of the
browser
field in theirpackage.json
to replace certain imports with others when running in a browser context throw an error.This is not an issue if the package defines
esmodules
,modern
,module
, ..., but occurs in the case of the axios package for example because they define only thebrowser
andmain
in theirpackage.json
.The issue also doesn't occur if the
browser
field is simply a string.To Reproduce
axios
package) and import it in any filenpm start
(oryarn run start
if that's more your cup of tea)Expected behavior
WMR bundles the package and handles the
browser
field correctly.Bug occurs with:
wmr
orwmr start
(development)wmr build
(production)wmr serve
Desktop (please complete the following information):
Additional context
Link to the spec that isn't handled correctly: https://github.com/defunctzombie/package-browser-field-spec#replace-specific-files---advanced
The following code is causing the issue:
wmr/packages/wmr/src/plugins/npm-plugin/resolve.js
Lines 10 to 17 in fd94818
resolve.exports
'slegacy
(imported as_resolveLegacyEntry
in this file) can also return aRecord<string, string | false>
due to thebrowser
field, which is not handled - the code tries to callreplace
on what is possibly an object, causing it to throw an error in cases like these.The text was updated successfully, but these errors were encountered: