Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exports order seems to matter #19217

Closed
7 tasks done
elmerbulthuis opened this issue Jan 17, 2025 · 1 comment
Closed
7 tasks done

Exports order seems to matter #19217

elmerbulthuis opened this issue Jan 17, 2025 · 1 comment

Comments

@elmerbulthuis
Copy link

Describe the bug

I have a dependency, it has the following exports in package.json:

  "exports": {
    ".": {
      "require": "./bundled/main.cjs",
      "import": "./bundled/main.js",
      "types": "./typed/main.d.ts",
      "browser": "./bundled/browser.js"
    }
  },

Vite always takes the import export. Now when I change this to:

  "exports": {
    ".": {
      "browser": "./bundled/browser.js",
      "import": "./bundled/main.js",
      "require": "./bundled/main.cjs",
      "types": "./typed/main.d.ts"
    }
  },

I get the desired and expected behavior, the browser export it used.

This is a bug, the order in which JSON fields are defined should not matter.

Reproduction

http://sorry.com

Steps to reproduce

No response

System Info

System:
    OS: Linux 6.6 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
    Memory: 7.15 GB / 15.48 GB
    Container: Yes
    Shell: 5.2.37 - /usr/bin/bash
  Binaries:
    Node: 23.4.0 - /usr/bin/node
    npm: 11.0.0 - /usr/bin/npm
  Browsers:
    Chromium: 132.0.6834.83
  npmPackages:
    @vitejs/plugin-react-swc: ^3.7.2 => 3.7.2
    rollup: ^3.29.5 => 3.29.5
    vite: ^5.4.11 => 6.0.7

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Jan 18, 2025

This behavior is written in the spec: https://nodejs.org/api/esm.html#:~:text=%20in%20object%20insertion%20order

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants