Skip to content

Package entry resolution fails when "browser" is an object #910

@rschristian

Description

@rschristian

Brought up by #909

When a package's "browser" field is an object, resolve.exports will return the entire object, not a string file path:

When true and "browser" is an object, then legacy() will return the the entire "browser" object.

See resolve.exports#optionsbrowser

This presents an issue in packages like bn.js:

package.json

...
"browser": {
  "buffer": false
},

function resolveLegacyEntry(pkg, path) {
const entry =
_resolveLegacyEntry(pkg, {
browser: true,
fields: ['esmodules', 'modern', 'module', 'jsnext:main', 'browser', 'main']
}) || 'index.js';
return '/' + entry.replace(/^\.?\//, '');
}

entry is { buffer: false }, not an import/file path. Besides the immediate issue of .replace not working, we'll need to fallback to "main" most likely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions