web icon indicating copy to clipboard operation
web copied to clipboard

WTR: `browser` exports are not resolved

Open tpluscode opened this issue 1 year ago • 0 comments

For example, trying to import [email protected] will fail because the node export will be resolved. Here's excerpt from the package.json

{
  "name": "nanoid",
  "exports": {
    ".": {
      "browser": "./index.browser.js",
      "default": "./index.js"
    },
    "./non-secure": "./non-secure/index.js",
    "./package.json": "./package.json"
  },
  "browser": {
    "./index.js": "./index.browser.js"
  },
  "react-native": {
    "./index.js": "./index.browser.js"
  }
}

The fix appears to add browser to node resolve plugin

export default {
  nodeResolve: {
    exportConditions: ['browser', 'module', 'import', 'default'],
  }
}

I think this could be made the default when setting nodeResolve: true

tpluscode avatar Nov 28 '24 13:11 tpluscode